Class: Collector
- Inherits:
-
Object
- Object
- Collector
- Defined in:
- lib/collector.rb
Instance Attribute Summary collapse
-
#collect ⇒ Object
Returns the value of attribute collect.
Instance Method Summary collapse
- #add(f) ⇒ Object
-
#initialize(procs, fin) ⇒ Collector
constructor
A new instance of Collector.
- #proc_finished ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(procs, fin) ⇒ Collector
Returns a new instance of Collector.
5 6 7 8 9 10 |
# File 'lib/collector.rb', line 5 def initialize(procs, fin) @procs = procs @finalize = fin @counter = 0 @collect = nil end |
Instance Attribute Details
#collect ⇒ Object
Returns the value of attribute collect.
3 4 5 |
# File 'lib/collector.rb', line 3 def collect @collect end |
Instance Method Details
#add(f) ⇒ Object
12 13 14 |
# File 'lib/collector.rb', line 12 def add(f) @procs.push(f) end |
#proc_finished ⇒ Object
22 23 24 25 26 27 |
# File 'lib/collector.rb', line 22 def proc_finished @counter += 1 if @procs.size == @counter @finalize.call(self) end end |
#start ⇒ Object
16 17 18 19 20 |
# File 'lib/collector.rb', line 16 def start @procs.each do |f| f.call(self) end end |