From: Wybo Dekker Date: 2006-02-23T00:06:05+09:00 Subject: Re: How to evaluate file as Ruby code? On Wed, 22 Feb 2006, Ronald Fischer wrote: > How do I evaluate a text file as a sequence of Ruby statements? > (For those who happen to know Perl: I would like to have an > equivalent of the Perl 'do FILENAME' feature). > > For example, I have a file "foo" which contains the lines > > abc=4 > def=5 > > I would like to "evaluate" the file such that after this, the > variable abc is set to 4 and def is set to 5. > > I tried the following: > > eval(File.new("foo").read) > > But after this, abc is still undefined. What am I doing wrong here? first, def=5 is a problem because def is a reserved word So make 'foo' to state a=4 b=5 and then try: a = b = nil eval(File.new('foo').read) puts "a=#{a} b=#{b}" -- Wybo