[ruby-core:96398] [Ruby master Feature#6810] `module A::B; end` is not equivalent to `module A; module B; end; end` with respect to constant lookup (scope)
From:
sawadatsuyoshi@...
Date:
2019-12-22 04:55:09 UTC
List:
ruby-core #96398
Issue #6810 has been updated by sawa (Tsuyoshi Sawada).
At lest as of Ruby 2.6.5, I get a different output from above for at least one of the examples:
```ruby
N = 0
module A
module B
def self.f; N; end
end
N = 1
end
N = 0
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-83322
* 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>