Module: InverseMethods

Defined in:
lib/version.rb,
lib/inverse_methods.rb

Constant Summary collapse

VERSION =
'0.0.2'

Instance Method Summary collapse

Instance Method Details

#chain_to(*syms) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/inverse_methods.rb', line 19

def chain_to(*syms)
  syms = syms[0] if syms[0].is_a?(Array)
  RubyVM::DebugInspector.open { |inspector|
    caller_context = inspector.frame_binding(2)
    initial_result = EvalProc.call syms.shift, self, caller_context
    syms.reduce(initial_result) { |result, sym|
      EvalProc.call sym, result, caller_context
    }
  }
end

#pass_to(*syms) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/inverse_methods.rb', line 10

def pass_to(*syms)
  syms = syms[0] if syms[0].is_a?(Array)
  RubyVM::DebugInspector.open { |inspector|
    caller_context = inspector.frame_binding(2)
    syms.each { |sym| EvalProc.call(sym, self, caller_context) }
  }
  self
end