From: Anurag Priyam Date: 2010-12-31T13:07:34+09:00 Subject: Re: Modules as namespaces > I'm sure I'm just missing some finer point of modules as namespaces. But can > someone explain to me why line 26 in http://pastie.org/1418890 gives an > error (uninitialized constant Bar::B::A), but line 25 doesn't? I thought the > two modules would have the same structure. Thanks! What you are missing is the way Ruby resolves the name of constants. It first tries to find the constant in the "lexical scope" of the reference - immediately enclosing module/class, then the next enclosing module/class, and so on. By defining Bar::B as "class Bar::B; end" and not "module Bar; class B; end; end" you are changing the scope in which the constant A should be resolved. You can find out the modules/classes that are searched by calling Module.nesting method; see http://pastie.org/1418923 -- Anurag Priyam, 3rd Year Undergraduate, Department of Mechanical Engineering, IIT Kharagpur. +91-9775550642