Sha256: cd4d762fa041bcb65bc2a2ea6fdabe1075f22f18d9f9c19317868bb6dbc702bd

Contents?: true

Size: 448 Bytes

Versions: 13

Compression:

Stored size: 448 Bytes

Contents

class RingBuffer < Array

  alias_method :array_push, :push
  alias_method :array_element, :[]

  def initialize( size )
    @ring_size = size
    super( size )
  end

  def push( element )
    if length == @ring_size
      shift # loose element
    end
    array_push element
  end

  # Access elements in the RingBuffer
  #
  # offset will be typically negative!
  #
  def []( offset = 0 )
    return self.array_element( - 1 + offset )
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
scout_realtime-1.0.5 lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-1.0.4 lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-1.0.3 lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-1.0.3.pre lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-1.0.2 lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-1.0.1 lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-1.0.0 lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-0.5.5 lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-0.5.5.pre lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-0.5.4 lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-0.5.3 lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-0.5.2 lib/scout_realtime/lib/ring_buffer.rb
scout_realtime-0.5.1 lib/scout_realtime/lib/ring_buffer.rb