From: Robert Klemme Date: 2004-01-22T04:24:59+09:00 Subject: Re: Modules as namespace "Hal Fulton" schrieb im Newsbeitrag news:400EBE6A.4080106@hypermetrics.com... > George Moschovitis wrote: > > Hello everyone, > > > > I would like to now if the following snippets of code are equivalent: > > > > ---> > > > > module My; module Little; module Namespace; > > > > class Foo > > end; > > > > end; end; end > > > > <--- > > > > module My::Little::Namespace; > > > > class Foo > > end; > > > > end; That doesn't work. However, you can do irb(main):003:0> module Outer; module Inner; end; end => nil irb(main):004:0> class Outer::Inner::Foo;end => nil irb(main):005:0> Outer::Inner::Foo.new => # > > are those snippets exactly the same? Ie i can do: > > > > foo = My::Little::Namespace::Foo.new? Yes, you can. But that's not the same as code snippet 1 and code snippet 2 are "exactly the same". :-) > First of all, you can only do this when the modules already > exist. (How should the interpreter know whether Little is > a class or module?) > > Second of all, I think you need parens because of a > precedence issue: > > foo = (My::Little::Namespace::Foo).new? > > Refer to a question I asked last week, something like "Nested > classes and the Singleton pattern", and see Nobu's reply. Hmmm... irb(main):001:0> module Outer; module Inner; class Foo; end; end; end => nil irb(main):002:0> Outer::Inner::Foo.new => # Regards robert