class Object
Public Instance Methods
downcast()
click to toggle source
Downcasts the object to the original class
@return the downcasted object (the original object)
# File lib/upcastable/core_ext/object/upcasting.rb, line 53 def downcast self end
upcast_to(ancestor)
click to toggle source
Upcasts the object to the specified class or module. Internally, the upcasted object is a Upcastable::UpcastedObject
instance which delegates almost all methods to the original object.
@param [Class, Module] ancestor the ancestor to which the object is upcasted @return the upcasted object @raise [ArgumentError] if ancestor
is not an ancestor
@example
module Animal def talk; end end class Cat include Animal def talk 'Meow!' end def run 'Running...' end end animal = Cat.new.upcast_to(Animal) animal.class #=> Cat animal.talk #=> "Meow!" animal.run #=> NoMethodError: `run' is not defined in Animal
# File lib/upcastable/core_ext/object/upcasting.rb, line 34 def upcast_to(ancestor) ::Upcastable::UpcastedObject.new(self, ancestor) end
upcasted?()
click to toggle source
Returns true if the object is upcasted
@return [true, false]
# File lib/upcastable/core_ext/object/upcasting.rb, line 46 def upcasted? false end
upcasting()
click to toggle source
@return [Class, Module, nil] the ancestor to which the object have been upcasted
# File lib/upcastable/core_ext/object/upcasting.rb, line 39 def upcasting nil end