Issue #6810 has been updated by kernigh (George Koehler).


My oldest Ruby 1.8.2 (2004-12-25) also says `A::B.f # => 1` for that example.  That Ruby is 15 years old.  The example showing `A::B.f # => 0` is 7 years old.  I suspect that `A::B.f # => 0` was a copy mistake, and Ruby always had `A::B.f # => 1`.

----------------------------------------
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-83464

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

```ruby
N = 0

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

  N = 1
end

A::B.f # => 1

N = 0

A::B.f # => 0

A::N = 1

A::B.f # => 1

A::B::N = 2

A::B.f # => 2
```

but

```ruby
N = 0

module A; end

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

module A
  N = 1
end

A::B.f # => 0

N = 0

A::B.f # => 0

A::N = 1

A::B.f # => 0

A::B::N = 2

A::B.f # => 2
```




-- 
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>