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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs