Class: Asuka::Accumulator

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

Instance Method Summary collapse

Constructor Details

#initializeAccumulator

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

Returns:

  • (Boolean)


11
12
13
# File 'lib/asuka/accumulator.rb', line 11

def empty?
  lines.empty?
end

#flush {|@lines| ... } ⇒ Object

Yields:

  • (@lines)


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