On Fri, Jul 11, 2008 at 3:13 PM, David A. Black <dblack / rubypal.com> wrote:
> The A::B::C notation does open that class body, but it compresses the
> nesting in such a way that the resolution logic just skips over it in
> one step and lands in the outer scope, where X is 1.

In case you (the OP that is, I'm sure David knows) are unsure where
Ruby looks when resolving constants, you can put a "p Module.nesting"
in the same scope as the constant reference. Constant resolution goes
somewhat as follows:

  def resolve_constant(nesting, constant)
    nesting << Object # Last resort
    Module.nesting.each do |m|
      m.ancestors.each do |a| # includes m too
        if a.const_defined?(constant)
          return a.const_get(constant) # const_get looks in the
ancestors as well; not needed here
        end
      end
    end
    nesting[0].const_missing(constant)
  end

  # These two should more or less be equivalent
  X
  resolve_constant(Module.nesting, :X)

Peter