Class: ItsIt::It
- Inherits:
- BasicObject
- Defined in:
- lib/its-it/it.rb
Overview
The class instantiated by the it
and its
kernel methods.
Defined Under Namespace
Modules: KeyValAccessors
Instance Method Summary collapse
- #===(obj) ⇒ Object
-
#initialize ⇒ It
constructor
:nodoc:.
- #method_missing(method, *args, **kw, &block) ⇒ Object
- #to_proc ⇒ Object
Constructor Details
#initialize ⇒ It
:nodoc:
17 18 19 |
# File 'lib/its-it/it.rb', line 17 def initialize #:nodoc: @queue = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kw, &block) ⇒ Object
21 22 23 24 |
# File 'lib/its-it/it.rb', line 21 def method_missing(method, *args, **kw, &block) @queue << [method, args, kw, block] unless method == :respond_to? and [:to_proc, :===].include?(args.first.to_sym) self end |
Instance Method Details
#===(obj) ⇒ Object
45 46 47 |
# File 'lib/its-it/it.rb', line 45 def ===(obj) self.to_proc.call(obj) end |
#to_proc ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/its-it/it.rb', line 35 def to_proc Kernel.send :proc do |*obj| case obj.size when 1 then obj = obj.shift # array comprehension, gets one arg when 2 then obj.extend(KeyValAccessors) # hash comprehension, gets two args end @queue.inject(obj) { |chain,(method, args, kw, block)| chain.send(method, *args, **kw, &block) } end end |