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.



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

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

Instance Attribute Details

#max_sizeObject (readonly)

Returns the value of attribute max_size.



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

def max_size
  @max_size
end

Instance Method Details

#dataObject



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

def data
  @data.dup
end

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



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

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