Class: ItsIt::It

Inherits:
Object
  • Object
show all
Defined in:
lib/its-it/it.rb

Overview

The class instantiated by the it and its kernel methods.

Instance Method Summary collapse

Constructor Details

#initializeIt

:nodoc:



19
20
21
# File 'lib/its-it/it.rb', line 19

def initialize #:nodoc:
  @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/its-it/it.rb', line 23

def method_missing(*args, &block)
  @methods << [args, block] unless args.first == :respond_to? and [:to_proc, :===].include?(args[1].to_sym)
  self
end

Instance Method Details

#===(obj) ⇒ Object



37
38
39
# File 'lib/its-it/it.rb', line 37

def ===(obj)
  self.to_proc.call(obj)
end

#to_procObject



28
29
30
31
32
33
34
35
# File 'lib/its-it/it.rb', line 28

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