Class: Asuka::Accumulator
- Inherits:
-
Object
- Object
- Asuka::Accumulator
- Defined in:
- lib/asuka/accumulator.rb
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #flush {|@lines| ... } ⇒ Object
-
#initialize ⇒ Accumulator
constructor
A new instance of Accumulator.
- #push(line) ⇒ Object
Constructor Details
#initialize ⇒ Accumulator
Returns a new instance of Accumulator.
3 4 5 |
# File 'lib/asuka/accumulator.rb', line 3 def initialize @lines = [] end |
Instance Method Details
#empty? ⇒ Boolean
11 12 13 |
# File 'lib/asuka/accumulator.rb', line 11 def empty? lines.empty? end |
#flush {|@lines| ... } ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/asuka/accumulator.rb', line 15 def flush return [] if empty? yield @lines if block_given? result, @lines = lines, [] result end |
#push(line) ⇒ Object
7 8 9 |
# File 'lib/asuka/accumulator.rb', line 7 def push(line) lines << line end |