Feature #6828
open
Added by trans (Thomas Sawyer) over 12 years ago.
Updated almost 4 years ago.
Description
=begin
Could have swore there was a recent issue addressing this, but couldn't find it, so...
I hope by Ruby 2.0
module Foo::Bar::Baz
will be equivalent to
module Foo; module Bar; module Baz
That constant lookup doesn't work the same for both is really really really annoying.
=end
Did you mean #6810 by any chance?
=begin
I think it might be implemented but i'd rather not do that.
The reason why its not equivalent is because the first statement means:
((|Define module Baz under Foo::Bar|))
The second one means:
((|Define module Foo, define module Bar under Foo, define module Baz under Foo::Bar|))
So it's not an issue in a common sense. In first case you try to create module under namespace that does not exist, that leads to error, and I think that's as it should be. In the second case you you explicitly define all module structure.
=end
=begin
It's not that. It's the constant lookup:
module Foo
X = 1
module Bar
p X #=> 1
end
end
module Foo::Bar
p X #=> NameError
end
Personally I would prefer undefined namespaces be automatically instantiated as modules. If that was not the intent another error will pick it up quickly enough anyway. But that's not the main issue --the constant lookup is the important thing.
=end
- Target version changed from 2.0.0 to 3.0
=begin
I rely on this feature of constant lookup.
It allows me to define (({File})) and other top-level constants in my library's namespace, but still use the top-level (({File})) without littering (({::})) everywhere in my library. It also helps me reduce confusion of contributors. They don't have to wonder if "File" is (({::File})) or (({MyLibrary::File})), it's always the top-level constant unless listed under my namespace. (In particular, RDoc has (({RDoc::Encoding})) and would break with this change.)
Changing the constant lookup will break ruby libraries that use this feature, so I have changed the target to 3.0
=end
- Target version deleted (
3.0)
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0