Project

General

Profile

Feature #6810

`module A::B; end` is not equivalent to `module A; module B; end; end` with respect to constant lookup (scope)

Added by alexeymuranov (Alexey Muranov) about 8 years ago. Updated 9 months ago.

Status:
Assigned
Priority:
Normal
Target version:
[ruby-core:79284]

Description

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

N = 0

A::B.f # => 0

A::N = 1

A::B.f # => 1

A::B::N = 2

A::B.f # => 2

but

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

Related issues

Has duplicate Ruby master - Feature #16430: Resultion of constants in enclosing class/module affected by how nested classes/modules are declaredRejectedActions

Also available in: Atom PDF