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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -