I read another question with an answer that mentions using the instance method Module#const_getto search for a class in a module. For instance:
module M
class C
end
end
p M.const_get 'C'
I was interested in the method const_get, so I used riand found:
ri Module#const_get
...
This method will recursively look up constant names if a namespaced
class name is provided. For example:
module Foo; class Bar; end end
Object.const_get 'Foo::Bar'
...
It appears to be Object::const_geta single point method. Using this in our context works:
module M
class C
end
end
p Object.const_get 'M::C'
But nothing is described about this singleton method:
ri Object::const_get
Nothing known about Object::const_get
ri Object.const_get
Nothing known about Object.const_get
This confused me because I know what Moduleis Object, but is Objectnot Module:
Module.ancestors
Object.ancestors
Also, I used the instance method Object#is_a?for validation and saw that I was wrong about this:
Module.is_a? Object
#=> true
Object.is_a? Module
#=> true
What started as an innocent request riled me to confusion throughout the entire Ruby object model.
Object.is_a? Module #=> true, Module Object?Object const_get?