Class: Binding

Inherits:
Object show all
Defined in:
lib/patch/let.rb

Overview

Enhances the Binding class to easily extract local variables into a Hash.

Instance Method Summary collapse

Instance Method Details

#variablesSymbol to Object

Converts the local variables accessible from this binding into a Hash. The keys of the hash are the variable names (as Symbols), and the values are the corresponding variable values.

Examples:

def my_method
  a = 10
  b = "hello"
  binding.variables # => {:a=>10, :b=>"hello"}
end


17
18
19
20
21
22
23
# File 'lib/patch/let.rb', line 17

def variables
  Hash[
    local_variables.map do |var|
      [var, local_variable_get(var)]
    end
  ]
end