From: pjb@... (Pascal J. Bourguignon) Date: 2008-10-13T23:12:11+09:00 Subject: Re: Namespacing my classes Zouplaz writes: > Hello, as I want to avoid name clashes I tried to organise them like > this (just a fake example, reflecting reality) > > lib/mylib.rb contains > module Mylib > > module TestDatas > FOO = "Ho yeah" > end > > require 'somelib/tools' > require 'somelib/motor' > end > > somelib/tools.rb contains > class Mylib::Tools > end > > somelib/motor.rb contains > class Mylib::Motor > > def something() > Mylib::TestDatas.FOO > end > > end > > > > Well, I did this by try/error until I had no more execution errors and > having them behaving as expected but is there any caveat ? > > I'm just suprised by the location of the requires statements You don't need to put these requires inside the module blocks. Instead, you could write: (module MyLib (module TestData (FOO = "abc") end) end) (module MyLib (class Tool end) end) (module MyLib (class Motor (def something (TestData::FOO) end) end) end) That is, if you avoid the (class Abc::Def::Ghi ... end) form, then modules namespaces will be created automatically when needed. Then, how you spread the forms over files and execute require is up to you and doesn't matter much. -- __Pascal Bourguignon__