Sha256: 4fe226436a2fa8001505803990b7b979fbdbcc8175185b6e1ac42d55689a5434

Contents?: true

Size: 366 Bytes

Versions: 4

Compression:

Stored size: 366 Bytes

Contents

module Fulmar
  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fulmar-shell-1.8.3 lib/fulmar/ringbuffer.rb
fulmar-shell-1.8.2 lib/fulmar/ringbuffer.rb
fulmar-shell-1.8.1 lib/fulmar/ringbuffer.rb
fulmar-shell-1.8.0 lib/fulmar/ringbuffer.rb