[ruby-core:79284] Re: [Ruby trunk Feature#6810] `module A::B; end` is not equivalent to `module A; module B; end; end` with respect to constant lookup (scope)

From: Daniel Ferreira <subtileos@...>
Date: 2017-01-27 12:16:36 UTC
List: ruby-core #79284
I agree Constant lookup is not easy in ruby.

What I use to do to avoid surprises is to request each external constant by
its full path:

```
N=0

module A; end

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

A::B.f # => NameError: uninitialized constant A::N

module A; N = 1; end

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

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

In This Thread