From: Joel VanderWerf Date: 2005-02-21T05:36:08+09:00 Subject: Re: Why don't I see these module constants? Lloyd Zusman wrote: > I think that it would be nice if in a future ruby release, the > two-argument form of load() would return the anonymous module. Then, Ruby being ruby, it's easy enough to add a feature like this. --------- class Module def load_in_module(file) module_eval(IO.read(file), File.expand_path(file)) end end m = Module.new m.load_in_module("some-file.rb") p m::X --------- where some-file.rb is: --------- X = 1 --------- I wrapped this up in a little library called "script" (a little small for RAA, but it's there), which adds a few other niceties: * instantiates the module and loads the file in one method call (whoopdeedo) * defines #require so that the loaded file can require files relative to its own directory * makes all methods defined in the file "module_functions" so that they are available in the form M.foo * autoload equivalent * can pass input to loaded files: script = Script.load("my-script.rb") { |script| script::INPUT = 3 }