From: Brian Mitchell Date: 2005-04-02T07:05:24+09:00 Subject: Re: Kernel.load() behaviour On Apr 1, 2005 2:44 PM, Andrew Walrond wrote: > On Friday 01 April 2005 22:37, Brian Mitchell wrote: > > On Apr 1, 2005 11:48 AM, Aredridel wrote: > > > > Not quite; Each of the 000s of packages is in it's own file.... ;) > > > > > > eval "module Packages\n" << `cat *.rb` << "\nend" > > > > > > ;-) > > > > module Packages > > end > > > > Packages.module_eval( `cat glibc.rb`, 'glibc.rb`) # A little more elegant. > > > > Almost perfect, but this avoids the external 'cat' dependency: > > Packages.module_eval( IO.readlines('glibc.rb').join, 'glibc.rb') > > I learned some more ruby today. Thanks all! One more idea that lets one use load and allows anonymous modules: glibc.rb: class Glibc end some_file.rb: module Packages end class Package def self.inherited(sub) Packages.const_set(sub.name.split("::").last, sub) end end load 'glibc.rb', true # Packages.constants == ["Glibc"] I also have an idea on how to do this with load my appending the anonymous module BUT I couldn't get Module.nesting to work and it seems ruby take some shortcuts in creation of the anon Module. If I can fix this then we'll all be able to load into specific modules which would be nice. Brian.