The best solution I’ve found is to read file1.rb and module_eval it’s
contents in the scope of a new module. Then, if you’ve defined constants
and methods in file1.rb, you can access them through the module. You
can’t get the local vars this way (which may be a good thing). (See the
script project on RAA for an elaboration of this approach.)
It’s also possible to assign to the local vars before loading file1.rb,
read file1.rb, eval it, and then the local variables will be updated.
But you have to know in advance what local variables file1.rb has:
ruby -e “x=1; eval ‘x=2;y=3’; p x, y”
-e:1: undefined local variable or method `y’ for main:Object (NameError)