I am trying to assign a variable within eval
, and then print it out. The code is:
eval "foo=nil"
puts foo
What I get is:
undefined local variable or method `foo' for main:Object (NameError)
When I use puts
within the eval
, I get no errors. This means that foo
is scoped within the eval
. How can I get it to be outside the eval
scope, yet not as a global variable?