Bug #11294
closedPossible bug in Object.const_get
Description
module Foo; end
module Foo::Baz; end
module Bar; end
module Bar::Qux; end
Object.const_get "Foo::Baz::Bar::Qux"
# => Bar::Qux
Why on earth it is found at all?
It seems pretty weird to me.
The real problem arises later, when I add Foo::Bar::Qux:
then the tree becomes as following:
But the result remains the same:
Here I'd expect searching "Foo::Baz::Bar::Qux" to
- either return nothing (this is less astonished, because there is no such constant),
- or find the closest
Bar::QuxtoFoo::Bar, that isFoo::Bar::Qux, not theBar::Qux
I cannot even understand the logic that follows the Object.const_get in providing such a result.
Updated by nobu (Nobuyoshi Nakada) about 11 years ago
- Description updated (diff)
- Status changed from Open to Rejected
Toplevel constants are defined under Object context, which are inherited by every contexts.
Your results are same as:
- or find the closest
Bar::QuxtoFoo::Bar, that isFoo::Bar::Qux, not theBar::Qux
It's not close.
And Foo::Baz::Bar is different from Foo::Bar.
Updated by nepalez (Andrew Kozin) about 11 years ago
Thank you, Nobuyoshi, for your answering. Now I see the reason.
When I told that Foo::Bar::Qux is "closest" to Foo::Baz I meant that in a namespace:
That's why I think it still be useful to have a "strict" version of Object.const_get that would treat the namespace literally with a syntax of sorts: