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.



10
11
12
# File 'lib/utils/grepper.rb', line 10

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

Instance Attribute Details

#max_sizeObject (readonly)

Returns the value of attribute max_size.



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

def max_size
  @max_size
end

Instance Method Details

#dataObject



16
17
18
# File 'lib/utils/grepper.rb', line 16

def data
  @data.dup
end

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



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

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