Module TypeCast::Class
In: lib/more/facets/typecast.rb

Typecast method extensions for Class class.

Methods

cast_from  

Public Instance methods

Cast on object from another.

  String.cast_from(1234) => "1234"

[Source]

# File lib/more/facets/typecast.rb, line 161
    def cast_from(object)
      method_to = "to_#{self.name.methodize}".to_sym
      if object.respond_to? method_to
        retval = object.send(method_to)
        return retval
      end
      method_from = "from_#{object.class.name.methodize}".to_sym
      if respond_to? method_from
        retval = send(method_from, object)
        return retval
      end
      raise TypeCastException, "TypeCasting from #{object.class.name} to #{self.name} not supported"
    end

[Validate]