Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Binding#local_variable_get

binding.local_variable_get(symbol) → obj

Returns the value of the local variable symbol.

Example
def foo
  a = 1
  binding.local_variable_get(:a) #=> 1
  binding.local_variable_get(:b) #=> NameError
end

This method is the short version of the following code:

Example
binding.eval("#{symbol}")