"Guillaume Marcais" <guslist / free.fr> schrieb im Newsbeitrag news:999F29CC-A344-11D8-B919-003065ED1070 / free.fr... > Le 11 mai 04, 07:38, Robert Klemme a ñÄrit : > > And then there is Kernel#load which already allows for wrapping in an > > anonymous module: > > http://www.ruby-doc.org/docs/rdoc/1.9/classes/Kernel.html#M001574 > > > > I'd rather suggest load to return the anonymous instance that was used > > in > > executing the code. That way, one can properly access all those > > methods > > defined in the file. > > And what about: > def load(file, wrap=false) > case wrap > when Module: # Wrap in this module > when true: # Wrap in an anonymous module and return it > else # Load normally > end Why doesn't this do the same trick? SomeModule.instance_eval do load 'thefile.ext' end Can anyone with a bit more insight than me shed some light on this? This works: Foo.instance_eval do eval File.read('mod.rb') end Foo.instance_eval File.read('mod.rb') 14:48:46 [ruby]: ./load_mod2.rb MAIN in main id=134728276 class=Object Loading... in Foo id=134689816 class=Module Loading... in Foo id=134689816 class=Module 14:49:50 [ruby]: cat load_mod2.rb #!/usr/bin/ruby puts "MAIN in #{inspect} id=#{id} class=#{self.class.inspect}" module Foo end Foo.instance_eval do eval File.read('mod.rb') end Foo.instance_eval File.read('mod.rb') 14:49:53 [ruby]: cat mod.rb #!/usr/bin/ruby puts "Loading... in #{inspect} id=#{id} class=#{self.class.inspect}" Kind regards robert