From: Joel VanderWerf Date: 2009-02-17T04:45:14+09:00 Subject: Re: load a Ruby source with params Cyril Beer wrote: > Do you know how loading a Ruby source with parameters? I had try so by > using: > load(my_file my_arg) It's a bit awkward, but there's a way to do it with my script library: http://redshift.sourceforge.net/script/ Quoting the docs: ========== An "input" can be passed to the script before loading. Simply call Script.new (or Script.load) with a block. The block is passed a single argument, the Script module, and executed before the files are loaded into the Script’s scope. Setting a constant in this block makes the constant available to the script during loading. For example: script = Script.load("my-script.rb") { |script| script::INPUT = 3 } ========== The file "my-script.rb" would simply refer to INPUT. You can pass any number of args this way. See the "program2.rb" in the examples/ dir for an example. As a bonus, everything defined in "my-script.rb" is wrapped in a module, returned by Script.load, and (in the case above) stored in a local variable in the main file, which you can use to access the constants and methods defined in my-script.rb. HTH. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407