From: Joel VanderWerf Date: 2008-07-07T14:32:13+09:00 Subject: Re: Accessing variables when loading a file to irb Joel VanderWerf wrote: > If > you need to load files from a program, and keep their instance (not > local) variables, constants, and methods in separate scopes, you might > be interested in these: > > http://raa.ruby-lang.org/project/script/ Ok, I said no local variables, but it's possible to expose them to the caller too, using eval(var_name, binding). So anyway, the 0.3 release of the above lets you do the following: $ cat prog.rb require 'script' script = Script.load("my-script.rb") p eval("x", script.__script_scope) p script.__local_variable_get(:x) p script.__local_variables p script.instance_variables $ cat my-script.rb x = 4 require 'my-script-sub' $ cat my-script-sub.rb x = 5 y = 6 $ ruby prog.rb 4 4 ["__file__", "x"] ["@__script_scope", "@__loaded_features", "@__dir", "@__main_file"] -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407