Module: Matrix::CoercionHelper
- Included in:
- Matrix
- Defined in:
- lib/matrix.rb
Overview
:nodoc:
Class Method Summary (collapse)
-
+ (Object) coerce_to(obj, cls, meth)
Helper method to coerce a value into a specific class.
- + (Object) coerce_to_int(obj)
Class Method Details
+ (Object) coerce_to(obj, cls, meth)
Helper method to coerce a value into a specific class. Raises a TypeError if the coercion fails or the returned value is not of the right class. (from Rubinius)
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
# File 'lib/matrix.rb', line 1092 def self.coerce_to(obj, cls, meth) # :nodoc: return obj if obj.kind_of?(cls) begin ret = obj.__send__(meth) rescue Exception => e raise TypeError, "Coercion error: #{obj.inspect}.#{meth} => #{cls} failed:\n" \ "(#{e.})" end raise TypeError, "Coercion error: obj.#{meth} did NOT return a #{cls} (was #{ret.class})" unless ret.kind_of? cls ret end |
+ (Object) coerce_to_int(obj)
1105 1106 1107 |
# File 'lib/matrix.rb', line 1105 def self.coerce_to_int(obj) coerce_to(obj, Integer, :to_int) end |