Issue #6810 has been updated by MikeVastola (Mike Vastola).


I just inadvertently made a dup of this issue (#16430) and would like to throw my hat in the ring as supporting this change. 

Honestly, this literally the first time since I started ruby that I encountered something in the language that was inherently non-intuitive. I'm also not sure I understand the use case for not including enclosing modules in the constant resolution hierarchy. 

One idea that I did have though is -- if this is seen as a breaking change (or otherwise difficult to implement with the current codebase) -- creating an alternate scope resolution operator (I was thinking `:::`) when defining modules where you want the scope resolution order to follow the hierarchy. 

----------------------------------------
Feature #6810: `module A::B; end` is not equivalent to `module A; module B; end; end` with respect to constant lookup (scope)
https://bugs.ruby-lang.org/issues/6810#change-83315

* Author: alexeymuranov (Alexey Muranov)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: Next Major
----------------------------------------
=begin
Is this the expected behavior?  To me it is rather surprising:

 N = 0

 module A
   module B
     def self.f; N; end
   end
   N = 1
 end

 A::B.f # => 1

but

 N = 0

 module A; end

 module A::B
   def self.f; N; end
 end

 module A
   N = 1
 end

 A::B.f # => 0

Even more striking:

 module A
   module B
     def self.f; N; end
   end
 end

 N = 0

 A::B.f # => 0

 A::N = 1

 puts A::B.f # => 1

 A::B::N = 2

 A::B.f # => 2

but

 module A; end

 module A::B
   def self.f; N; end
 end

 N = 0

 A::B.f # => 0

 A::N = 1

 A::B.f # => 0

 A::B::N = 2

 A::B.f # => 2


=end



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>