Sha256: b6c276a79ef90881996a50ccad23b322d59fc5e8c0974487e4f031d7d1ae84ad

Contents?: true

Size: 316 Bytes

Versions: 6

Compression:

Stored size: 316 Bytes

Contents

class RingBuffer < Array
  attr_reader :max_size

  def initialize(max_size, enum = nil)
    @max_size = max_size
    enum.each { |e| self << e } if enum
  end

  def <<(el)
    if self.size < @max_size || @max_size.nil?
      super
    else
      self.shift
      self.push(el)
    end
  end

  alias :push :<<
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
logstash-output-jdbc-0.2.0.rc4 lib/logstash-output-jdbc_ring-buffer.rb
sq_ruby_grep-0.0.7 lib/sq_ruby_grep/ring_buffer.rb
sq_ruby_grep-0.0.6 lib/sq_ruby_grep/ring_buffer.rb
sq_ruby_grep-0.0.5 lib/sq_ruby_grep/ring_buffer.rb
sq_ruby_grep-0.0.4 lib/sq_ruby_grep/ring_buffer.rb
sq_ruby_grep-0.0.3 lib/sq_ruby_grep/ring_buffer.rb