Module: Matrix::CoercionHelper
Do not use. This module is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/matrix.rb |
Class Method Summary
-
.coerce_to(obj, cls, meth)
Helper method to coerce a value into a specific class.
- .coerce_to_int(obj)
- .coerce_to_matrix(obj)
Instance Method Summary
-
#apply_through_coercion(obj, oper)
private
Applies the operator
oper
with argumentobj
through coercion ofobj
Class Method Details
.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)
# File 'lib/matrix.rb', line 1528
def self.coerce_to(obj, cls, meth) # :nodoc: return obj if obj.kind_of?(cls) raise TypeError, "Expected a #{cls} but got a #{obj.class}" unless obj.respond_to? meth 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
.coerce_to_int(obj)
[ GitHub ]# File 'lib/matrix.rb', line 1541
def self.coerce_to_int(obj) coerce_to(obj, Integer, :to_int) end
.coerce_to_matrix(obj)
[ GitHub ]Instance Method Details
#apply_through_coercion(obj, oper) (private)
Applies the operator oper
with argument obj
through coercion of obj