From: Robert Dober Date: 2008-02-13T05:14:44+09:00 Subject: Re: Ruby equivalent to source command On Feb 12, 2008 7:47 PM, Joel VanderWerf wrote: > Brett Williams wrote: > > I figured this was the case. I'll go with globals for my context. > > The horror, the horror. I agree, i agree ;) > > Here's an alternative: http://redshift.sourceforge.net/script. It does not seem to handle OP's problem though, which are locals or am I wrong? My idea would be to use Smalltalk constants, does anybody save Rick know what that is? ;) But of course constants are not enough so I will define setters too :) But I am not sure if that works let me see: Yup seems to work file: test1.rb a="sourced a" b="sourced b" file: main.rb a = "Main a" eval File.open("test1.rb"){|f| f.read } << %{ local_variables.each do |lvar| this = class << self; self end this.send :define_method, lvar do eval lvar end this.send :define_method, lvar + "=" do |new_val| lvar = new_val end end } p [:now_a, a] p [:now_b, b] b = "changed" p [:changed_b, b] ---------------------------------------------------------------- Now it depends very much on the use case if you can live with this. Any pitfalls I have overseen? HTH Robert > > -- > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407 > > -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein