Class: It

Inherits:
BasicObject
Defined in:
lib/slab/methodphitamine.rb

Instance Method Summary collapse

Constructor Details

#initializeIt

Returns a new instance of It.



11
12
13
# File 'lib/slab/methodphitamine.rb', line 11

def initialize
  @methods = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



15
16
17
18
# File 'lib/slab/methodphitamine.rb', line 15

def method_missing(*args, &block)
  @methods << [args, block] unless args == [:respond_to?, :to_proc]
  self
end

Instance Method Details

#to_procObject



20
21
22
23
24
# File 'lib/slab/methodphitamine.rb', line 20

def to_proc
  ::Kernel.lambda do |obj|
    @methods.inject(obj) { |current, (args,block)| current.send(*args, &block) }
  end
end