Class: Methodphitamine::It

Inherits:
Object
  • Object
show all
Defined in:
lib/methodphitamine/it_class.rb

Overview

The class instantiated by the it() and its() methods from monkey_patches.rb.

Direct Known Subclasses

MethodphitamineMaybe

Instance Method Summary collapse

Constructor Details

#initializeIt

Returns a new instance of It.



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

def initialize
  @methods = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



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

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

Instance Method Details

#methodphitamine_queueObject

Used for testing this class.



37
38
39
# File 'lib/methodphitamine/it_class.rb', line 37

def methodphitamine_queue
  @methods
end

#to_procObject



28
29
30
31
32
33
34
# File 'lib/methodphitamine/it_class.rb', line 28

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