From: dblack@... Date: 2003-05-13T23:42:47+09:00 Subject: Re: Scope of modules and classes Hi -- On Tue, 13 May 2003, Bernhard Weitzhofer wrote: > Hello Ruby-community > > I am writing a set of classes to be used in a mod_ruby environment, and > I decided to group them together in a module: [...] > So far so good - but then I wanted to get rid of all those "M::"s: > > module M2 > include M > > class K3 < K1 > def initialize > @a = K2.new > @b = K2.new > end > end > > ... > end > > does not work (K2 is unknown in the scope of K3), and: > > module M2 > class K3 < M::K1 > include M > def initialize > @a = K2.new > @b = K2.new > end > end > > ... > end > > seems a little bit ugly to me since I have to include M in every class of M2 > > Is there a better way, should I stick to the "M::"s, or is it just bad > design that I am doing here? Looking at the design aspect of it, you could put M2 inside M (since it seems to want to be there :-) if it makes sense in the larger picture. module M class K1 end class K2 def initialize puts "Initializing a #{self.class}!" end end module M2 class K3 < K1 def initialize @a = K2.new end end end end include M M2::K3.new (For those last two lines you could also do include M::M2 K3.new or just M::M2::K3.new ) David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav