Class: It

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

Instance Method Summary collapse

Constructor Details

#initializeIt

Returns a new instance of It.



14
15
16
# File 'lib/vendor/methodphitamine.rb', line 14

def initialize
  @methods = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



18
19
20
21
# File 'lib/vendor/methodphitamine.rb', line 18

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

Instance Method Details

#to_procObject



23
24
25
26
27
# File 'lib/vendor/methodphitamine.rb', line 23

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