Class: Line::QueueWithIndexes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/line/queue_with_indexes.rb

Instance Method Summary collapse

Constructor Details

#initialize(num_negatives = 0, &input_generator) ⇒ QueueWithIndexes

Returns a new instance of QueueWithIndexes.



3
4
5
6
7
8
# File 'lib/line/queue_with_indexes.rb', line 3

def initialize(num_negatives=0, &input_generator)
  self.positive_index  = 0
  self.buffer          = []
  self.num_negatives   = num_negatives
  self.input_generator = input_generator
end

Instance Method Details

#each(&block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/line/queue_with_indexes.rb', line 12

def each(&block)
  return to_enum :each unless block
  fill_the_buffer             until dry_generator? || full_buffer?
  flow_through_buffer(&block) until dry_generator?
  drain_the_buffer(&block)    until empty?
  self
end

#empty?Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/line/queue_with_indexes.rb', line 20

def empty?
  fill_the_buffer
  buffer.empty?
end