From: ChrisH Date: 2006-02-22T23:23:37+09:00 Subject: Re: How to evaluate file as Ruby code? 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? > > Ronald require will load and evaluate the file once, but will not load a file that has already been 'require'd load will load and evaluate the file, it will reload and re-evaluate. Cheers Chris