[Ruby] eval question
James Moore
banshee at banshee.com
Mon Apr 30 15:04:09 PDT 2007
Is irb confusing the issue?
irb(main):001:0> eval "x = 'y'"
=> "y"
irb(main):002:0> x
=> "y"
But:
(in el.rb)
eval "x = 'y'"
puts x.inspect
C:\rx\rfs>ruby bin/el.rb
bin/el.rb:2: undefined local variable or method `x' for main:Object
(NameError)
C:\rx\rfs>ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
- James Moore
-----Original Message-----
From: ruby-bounces at zenspider.com [mailto:ruby-bounces at zenspider.com] On
Behalf Of Ryan Davis
Sent: Monday, April 30, 2007 3:05 PM
To: Seattle Ruby Brigade!
Subject: Re: [Ruby] eval question
On Apr 30, 2007, at 13:09 , Aaron Patterson wrote:
> In this code, 'easy_lover' is defined, but for some reason
> 'phil_collins' is not. First, why is that? Second, can I make it so?
> You can have Easy Lover without Phil!
What version of ruby??
% irb
>> eval(<<-END
phil_collins = 'awesome'
def easy_lover
"She'll get a hold on you believe it"
end
END
>> )
=> nil
>> phil_collins
=> "awesome"
>> RUBY_VERSION
=> "1.8.5"
_______________________________________________
Ruby at zenspider.com - Seattle.rb non-commercial list
http://www.zenspider.com/seattle.rb
http://www.zenspider.com/mailman/listinfo/ruby
More information about the Ruby
mailing list