Dynamically set local variables in Ruby [duplicate]
As an additional information for future readers, starting from ruby 2.1.0 you can using binding.local_variable_get and binding.local_variable_set: def foo a = 1 b = binding b.local_variable_set(:a, 2) # set existing local variable `a’ b.local_variable_set(:c, 3) # create new local variable `c’ # `c’ exists only in binding. b.local_variable_get(:a) #=> 2 b.local_variable_get(:c) #=> 3 p a … Read more