Project

General

Profile

Actions

Feature #6810

open

`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) over 12 years ago. Updated almost 4 years ago.

Status:
Assigned
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 1 (0 open1 closed)

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0