class RorHack::LookupStack

Public Class Methods

new(bindings = []) click to toggle source
# File lib/ror_hack/proc_hack.rb, line 3
def initialize(bindings = [])
  @bindings = bindings
end

Public Instance Methods

method_missing(m, *args) click to toggle source
# File lib/ror_hack/proc_hack.rb, line 7
def method_missing(m, *args)
  @bindings.reverse_each do |bind|
    begin
      method = eval("method(%s)" % m.inspect, bind)
    rescue NameError
    else
      return method.call(*args)
    end
    begin
      value = eval(m.to_s, bind)
      return value
    rescue NameError
    end
  end
  raise NoMethodError
end
push_binding(bind) click to toggle source
# File lib/ror_hack/proc_hack.rb, line 24
def push_binding(bind)
  @bindings.push bind
end
push_hash(vars) click to toggle source
# File lib/ror_hack/proc_hack.rb, line 32
def push_hash(vars)
  push_instance Struct.new(*vars.keys).new(*vars.values)
end
push_instance(obj) click to toggle source
# File lib/ror_hack/proc_hack.rb, line 28
def push_instance(obj)
  @bindings.push obj.instance_eval { binding }
end
run_proc(p, *args) click to toggle source
# File lib/ror_hack/proc_hack.rb, line 36
def run_proc(p, *args)
  instance_exec(*args, &p)
end