Project

General

Profile

Actions

Feature #6828

open

Constancy of Constants

Added by trans (Thomas Sawyer) over 11 years ago. Updated over 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:46967]

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

Updated by alexeymuranov (Alexey Muranov) over 11 years ago

Did you mean #6810 by any chance?

Updated by MasterLambaster (Alex N) over 11 years ago

=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

Updated by trans (Thomas Sawyer) over 11 years ago

=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

Updated by trans (Thomas Sawyer) over 11 years ago

@alexeymuranov (Alexey Muranov) Yes, #6810 that's the one. Probably why I did not find it --it listed as a Bug. I would agree, actually.

Updated by drbrain (Eric Hodel) over 11 years ago

  • 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

Actions #6

Updated by naruse (Yui NARUSE) over 3 years ago

  • Target version deleted (3.0)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0