title: Why does Ruby not add parent modules to the lexical scope for constant lookup when using double colons?
body: <p>This question is an extension of <a href="https://stackoverflow.com/questions/59273879/ruby-class-namespacing-with-modules-why-do-i-get-nameerror-with-double-colons-b">this</a> question. The answer helped me understand what was happening, but I am still questioning why. </p>
  
  <p>When defining two classes within a module there are two ways to write it.</p>
  
  <p><strong>Using Module Blocks:</strong></p>
  
  <pre><code>module Foo
    class FirstClass
      def meth
        puts 'HELLO'
      end
    end
  
    class SecondClass
      def meth
        FirstClass.new.meth
      end
    end
  end
  
  Foo::SecondClass.new.meth
  </code></pre>
  
  <p><strong>Using Double Colons:</strong></p>
  
  <pre><code>module Foo; end
  
  class Foo::FirstClass
    def meth
      puts 'HELLO'
    end
  end
  
  class Foo::SecondClass
    def meth
      FirstClass.new.meth
    end
  end
  
  Foo::SecondClass.new.meth
  
  </code></pre>
  
  <p>Both ways work for class definition, but when using double colons you cannot directly lookup <code>FirstClass</code> inside of <code>SecondClass</code> without including <code>FirstClass</code> or writing <code>Foo::FirstClass</code>. This happens because <code>Foo</code> is not a part of the lexical scope of <code>SecondClass</code> when it's defined with double colons, which can be demonstrated by using <code>Module.nesting</code>. </p>
  
  <p>Why is <code>Foo</code> not added to the lexical scope with double colons? In the context of the lower level Ruby <a href="https://ruby-hacking-guide.github.io/module.html" rel="noreferrer">source code</a>, why does <code>ruby_cref</code> point only to <code>Foo::SecondClass</code> instead of <code>ruby_cref</code> pointing to <code>SecondClass</code> which then points to <code>Foo</code>? </p>
  
  <p><strong>For Example:</strong></p>
  
  <pre><code>+---------+       +---------+
  | nd_next | &lt;-----+ nd_next | &lt;----+  ruby_cref
  | nd_clss |       | nd_clss |
  +----+----+       +----+----+
       |                 |
       |                 |
       v                 v
      Foo            SecondClass
  </code></pre>