Difference between classes and constants in ruby w.r.t const_get? -
why const_get(class_name)
return actual class, though const_get
method supposed return constant of given name. ruby store classes constants, or else?
no, const_get
not return constant. constants not objects, cannot return them. const_get
does, returns object constant points to. in other words,
const_get(:foo)
is more or less same
foo
and if object constants points happens class, then, yes, const_get
return class. if object constant points happens else, const_get
return else.
foo = 'not class' bar = class.new const_get(:foo) # => 'not class' const_get(:bar) # => bar
Comments
Post a Comment