Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Binding#local_variable_get

(::interned varname) -> untyped
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}")