class Utils::Grepper::Queue

maximum size is exceeded, the oldest item is automatically removed.
The Queue class provides a fixed-size buffer for storing objects. When the
“item2” # … queue.data # => [ “item1”, “item2”, … ]
@example queue = Utils::Grepper::Queue.new(5) queue << “item1” queue <<
A queue implementation with size limitation.

def data

Returns:
  • (Array) - a duplicate of the internal data array
def data
  @data.dup
end

def initialize(max_size)

Parameters:
  • max_size (Integer) -- the maximum size limit for the data storage
def initialize(max_size)
  @max_size, @data = max_size, []
end

def push(x)

Returns:
  • (Queue) - returns self to allow for method chaining

Parameters:
  • x (Object) -- the element to be added to the queue
def push(x)
  @data.shift if @data.size > @max_size
  @data << x
  self
end