From: Lloyd Zusman Date: 2005-02-20T07:47:29+09:00 Subject: Re: Dynamically loading and executing within a new module? Lloyd Zusman writes: > ES writes: > >> >> [ ... ] >> >> If you don't just want to write an actual module and then call its #init, >> you could do something like this. Somewhat pseudo: >> >> Thread.new do >> if fname >> mod = eval fname.capitalize >> data = File.new(fname, 'r') do |f| >> f.read >> end >> mod.module_eval data >> mod.send :init, args >> # ... >> end >> end >> >> Or sumptin :) > > Thanks. This makes sense. > > However, the "eval fname.capitalize" part doesn't create a new module, > and that's part of what is confusing me about all this. Given a string > "Foo", what do I do to it in order to create a module object with that > name? Actually, I now realize that I don't need a bona fide named module, but rather, just a way to associate a name with a module. Therefore, I think that I can do it more or less like this: modhash = Hash.new if fname then if modhash.has_key?(fname) then mod = modhash[fname] else mod = Module.new modhash[fname] = mod end data = File.new(fname, 'r') do |f| f.read end mod.module_eval data mod.send :init, args end Does this make sense? -- Lloyd Zusman ljz@asfast.com God bless you.