I am trying to dynamically create local variables in Ruby using eval and mutate the local-variables array. I am doing this in IRB.
eval
eval \"t = 2\
You have to synchronize the evaluations with the same binding object. Otherwise, a single evaluation has its own scope.
b = binding eval("t = 2", b) eval("local_variables", b) #=> [:t, :b, :_] eval("t", b) # => 2 b.eval('t') # => 2