On 7/17/06, Thorben Mueller <dingsi / mistburg.de> wrote:
> Rick Ashton schrieb:
> > Thanks guys
> >
> > But it still doesn't load the file into the current scope as I mentioned
> > before. Is there some way to do this?
> >
> > ie:
> >
> > $ echo a=5 > blah.rb
> > $ irb -r blah.rb
> > irb(main):001:0> a
> > NameError: undefined local variable or method `a' for main:Object
> >         from (irb):1
> >
> >
> > Thanks!
> >
>
> Hi Rick,
>
> try eval(File.read('blah.rb'))
>
> ~dingsi
>
>

eval() won't create local variables - it will update one if it already
exists however:

$ cat eval-test.rb
a = 42
$ cat eval-scope.rb
eval(File.read("eval-test.rb"))
p a
$ ruby eval-scope.rb
eval-scope.rb:2: undefined local variable or method `a' for
main:Object (NameError)

$ cat eval-scope2.rb
a = nil
eval(File.read("eval-test.rb"))
p a
$ ruby eval-scope2.rb
42


Regards,
Sean