class MethodChainable::Proxy
Attributes
input[RW]
m_chain_count[RW]
m_chainable[RW]
output[RW]
Public Class Methods
new(m_chainable, input)
click to toggle source
# File lib/method_chainable/proxy.rb, line 14 def initialize(m_chainable, input) @m_chainable = m_chainable @output = output @input = input @m_chain_count = 0 end
Public Instance Methods
method_missing(m, *args, &block)
click to toggle source
Remembers the output of the previous call and passes on to the new one
Calls superclass method
# File lib/method_chainable/proxy.rb, line 33 def method_missing(m, *args, &block) m = m.to_s # Return the final output if value is called if m == 'val' return output else # Since value is not called yet keep calling # the actual method on chainable and pass # the previous output if m_chainable.respond_to? m arg = (@m_chain_count == 0) ? input : output arity = m_chainable.method(m).arity if arity > 0 @output = m_chainable.send(m, arg) else @output = m_chainable.send(m) end @m_chain_count += 1 return self else super(m, *args, &block) end end end