Class: Ze

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

Defined Under Namespace

Classes: CallMethod

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first_method, *args, &block) ⇒ Ze

Returns a new instance of Ze.



12
13
14
# File 'lib/ze.rb', line 12

def initialize(first_method, *args, &block)
  @stack = [CallMethod.new(first_method, args, block)]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



16
17
18
19
# File 'lib/ze.rb', line 16

def method_missing(next_method, *args, &block)
  @stack << CallMethod.new(next_method, args, block)
  self
end

Class Method Details

.method_missing(method_name, *args, &block) ⇒ Object



8
9
10
# File 'lib/ze.rb', line 8

def self.method_missing(method_name, *args, &block)
  self.new(method_name, *args, &block)
end

Instance Method Details

#call(target) ⇒ Object Also known as: ===, []



25
26
27
# File 'lib/ze.rb', line 25

def call(target)
  @stack.reduce(target) { |t, cm| t.send(cm.method_name, *cm.args, &cm.block) }
end

#to_procObject



21
22
23
# File 'lib/ze.rb', line 21

def to_proc
  proc { |target| self.call(target) }
end