Class: Uberscore::Context

Inherits:
BasicObject
Defined in:
lib/uberscore.rb

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



16
17
18
# File 'lib/uberscore.rb', line 16

def initialize
  @call_chain = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



20
21
22
23
# File 'lib/uberscore.rb', line 20

def method_missing(name, *args, &block)
  @call_chain << [name, args, block]
  self
end

Instance Method Details

#to_procObject



25
26
27
28
29
30
31
# File 'lib/uberscore.rb', line 25

def to_proc
  ->(object) do
    @call_chain.reduce(object) do |current, (name, args, block)|
      current.public_send(name, *args, &block)
    end
  end
end