Class: Stages::Each
Instance Attribute Summary
Attributes inherited from Stage
#source
Instance Method Summary
collapse
Methods inherited from Stage
#die, #done?, #drop_leftmost!, #each, #end?, #handle_value, #initialize_loop, #input, #length, #output, #reset, #root_source, #run, #source_empty?, #to_enum, #|
Constructor Details
#initialize(things = nil, &block) ⇒ Each
Returns a new instance of Each.
3
4
5
6
7
|
# File 'lib/stages/each.rb', line 3
def initialize(things = nil, &block)
@things = things unless things.nil?
@block = block
super()
end
|
Instance Method Details
#process ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/stages/each.rb', line 9
def process
if @things
process_things
else
process_inputs
end
end
|
17
18
19
20
21
22
23
24
25
|
# File 'lib/stages/each.rb', line 17
def process_inputs
while !source_empty?
v = input
v = @block.call(v) if @block
v.each do |v|
handle_value v
end
end
end
|
#process_things ⇒ Object
27
28
29
30
31
32
|
# File 'lib/stages/each.rb', line 27
def process_things
@things = @block.call(@things) if @block
@things.each do |thing|
handle_value thing
end
end
|