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