Class: Utils::Grepper::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/grepper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_size) ⇒ Queue

Returns a new instance of Queue.


14
15
16
# File 'lib/utils/grepper.rb', line 14

def initialize(max_size)
  @max_size, @data = max_size, []
end

Instance Attribute Details

#max_sizeObject (readonly)

Returns the value of attribute max_size


18
19
20
# File 'lib/utils/grepper.rb', line 18

def max_size
  @max_size
end

Instance Method Details

#dataObject


20
21
22
# File 'lib/utils/grepper.rb', line 20

def data
  @data.dup
end

#push(x) ⇒ Object Also known as: <<


24
25
26
27
28
# File 'lib/utils/grepper.rb', line 24

def push(x)
  @data.shift if @data.size > @max_size
  @data << x
  self
end