method
local_variable_set
v2_1_10 -
Show latest stable
-
0 notes -
Class: Binding
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10 (0)
- 2_2_9 (38)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
local_variable_set(p1, p2)
public
Set local variable named symbol as obj.
def foo a = 1 b = binding b.local_variable_set(:a, 2) # set existing local variable `a' b.local_variable_set(:b, 3) # create new local variable `b' # `b' exists only in binding. b.local_variable_get(:a) #=> 2 b.local_variable_get(:b) #=> 3 p a #=> 2 p b #=> NameError end
This method is a similar behavior of the following code
binding.eval("#{symbol} = #{obj}")
if obj can be dumped in Ruby code.