Christopher J. Bottaro
2008-May-22 03:39 UTC
Why can''t I define vars in caller''s binding using eval?
In other words, why can''t I do this?
def f(b)
eval("x = 10", b)
end
f(binding)
puts "x = #{x}"
Is there any way to make that code work (besides obviously setting x
to something before calling f).
Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-22 09:21 UTC
Re: Why can''t I define vars in caller''s binding using eval?
On 22 May 2008, at 04:39, Christopher J. Bottaro wrote:> > In other words, why can''t I do this? > > def f(b) > eval("x = 10", b) > end > > f(binding) > puts "x = #{x}" >This seems relevant: http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/a954f8aaf698a0b9/e1c761b71b63b82e?#e1c761b71b63b82e Fred> Is there any way to make that code work (besides obviously setting x > to something before calling f). > > Thanks. > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---