Assigning a instance variable using eval works fine whereas the other doesn't. Trying to understand whats happening here. Any help is appreciated.
>> var = "a value"
=> "a value"
>> @v
=> nil
>> eval "@v = var"
=> "a value"
>> @v
=> "a value"
>> eval "var_new = var"
=> "a value"
>> var_new
NameError: undefined local variable or method `var_new' for main:Object
from (irb):7
from C:/Ruby193/bin/irb:12:in `<main>'
evalcreates a new scope andvar_newis local to that scope.@vis an instance variable of the containing object (insideirbthat's an instance ofObject- at least it is in 1.8.7), so it can be accessed from eval, and remains afterwards due to being scoped to the object.