Class: Proc::Composition::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/proc/composition/evaluator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEvaluator



8
9
10
# File 'lib/proc/composition/evaluator.rb', line 8

def initialize
  @callables = []
end

Instance Attribute Details

#callablesObject (readonly)

Returns the value of attribute callables.



6
7
8
# File 'lib/proc/composition/evaluator.rb', line 6

def callables
  @callables
end

Instance Method Details

#<<(proc) ⇒ Object



22
23
24
# File 'lib/proc/composition/evaluator.rb', line 22

def <<(proc)
  @callables << proc
end

#>>(other) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/proc/composition/evaluator.rb', line 26

def >>(other)
  evaluator = dup

  case other
  when Evaluator
    other.callables.each do |each_callable|
      evaluator << each_callable
    end
  when Callable
    evaluator << Deferable.new(other.proc)
  end

  evaluator
end

#[](proc) ⇒ Object



16
17
18
19
20
# File 'lib/proc/composition/evaluator.rb', line 16

def [](proc)
  evaluator = dup
  evaluator << Deferable.new(proc)
  evaluator
end

#call(**arguments) ⇒ Object



41
42
43
44
45
# File 'lib/proc/composition/evaluator.rb', line 41

def call(**arguments)
  evaluator = dup
  evaluator.callables.last.arguments = arguments
  evaluator
end

#initialize_copy(_) ⇒ Object



12
13
14
# File 'lib/proc/composition/evaluator.rb', line 12

def initialize_copy(_)
  @callables = @callables.map(&:dup)
end

#serializeObject



47
48
49
# File 'lib/proc/composition/evaluator.rb', line 47

def serialize
  @callables.map(&:serialize)
end