Trying to switch a project of mine from python to ruby. Love ruby so
far, but I’m finding that the eval statement is a bit more difficult to
use than python’s exec statement. Here is one of the problems I’m
a = 1
This will print out ‘2’, as I want. However if I remove the first line,
<main>': undefined local variable or methoda’ for
Now if in the first case eval can change a variable in its scope, why
can’t it also create a variable in that same scope? I may also not be
totally clear on the way ruby handles scoping, which might be part of
what I am having trouble understanding.
Any help understanding the eval statement would be appreciated. I will
probably have more questions about it, but I’ll leave at this for now.