Skip to content

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

instance method

Binding#local_variables

binding.local_variables → Array

Returns the names of the binding’s local variables as symbols.

Example
def foo
  a = 1
  2.times do |n|
    binding.local_variables #=> [:a, :n]
  end
end

This method is the short version of the following code:

Example
binding.eval("local_variables")