Class: Binding

Inherits:
Object show all
Defined in:
lib/epitools/core_ext/misc.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Get a variable in this binding



18
19
20
# File 'lib/epitools/core_ext/misc.rb', line 18

def [](key)
  eval(key.to_s)
end

#[]=(key, val) ⇒ Object

Set a variable in this binding



25
26
27
28
29
# File 'lib/epitools/core_ext/misc.rb', line 25

def []=(key, val)
  Thread.current[:_alter_binding_local_] = val
  eval("#{key} = Thread.current[:_alter_binding_local_]")
  Thread.current[:_alter_binding_local_] = nil
end

#local_variablesObject Also known as: keys



35
36
37
# File 'lib/epitools/core_ext/misc.rb', line 35

def local_variables
  eval("local_variables").map(&:to_sym)
end

#merge(other) ⇒ Object Also known as: |

Combine the variables in two bindings (the latter having precedence)



49
50
51
52
53
54
55
# File 'lib/epitools/core_ext/misc.rb', line 49

def merge(other)
  self.eval do
    other.eval do
      binding
    end
  end
end