On Dec 17, 11:47 am, MonkeeSage <MonkeeS... / gmail.com> wrote: > On Dec 17, 12:07 pm, Phrogz <phr... / mac.com> wrote: > > > > > I was surprised by the following this weekend: > > > module Foo > > module Bar; end > > class Whee1 > > include Bar > > end > > end > > # All is well > > > class Foo::Whee2 > > include Bar > > end > > #=> uninitialized constant Foo::Whee2::Bar (NameError) > > > Is the answer simply "lexically scoped resolution"? > > > Is the above still the case with 1.9? > > Maybe it's because (I assume) this is a paired-down example, but in > the example class Whee1 is in the scope of module Foo, and so is > module Bar, but module Bar isn't in the scope of class Foo::Whee2, so > you have to include it as qualified Foo::Bar. It doesn't look like > module Bar is lexically scoped to class Foo. The actual situation was that I started writing code all nested as in the first example. Everything was working, my unit tests were passing, all was right with the world. But I didn't like the nesting. The extra level of folding was getting in the way, and the non-explicit nesting made my function pop up not the way I wanted. So I changed the code in a way that I thought was purely formatting; I pulled the classes (and modules) out to the top level with an explicit Foo:: prefix for each. And I was surprised when my code stopped working. It was simple enough to see the error, and not very painful to find all the cases where I had included the module and also add the Foo:: prefix. But it surprised me. Despite likely reading about this issue previously, I had thought constant resolution would not be affected by that particular edit. *shrug*