class RingBuffer
Constants
- VERSION
Attributes
max_size[R]
Public Class Methods
new(max_size)
click to toggle source
# File lib/ring_buffer.rb, line 8 def initialize(max_size) raise 'max_size must be an integer' if !max_size.is_a? Integer raise 'max_size must be positive' if max_size < 0 @max_size = max_size end
Public Instance Methods
<<(element)
click to toggle source
Calls superclass method
# File lib/ring_buffer.rb, line 15 def <<(element) return super(element) if size < @max_size # If the RingBuffer is full, remove the first element and add the new at the end. shift push element end
Also aliased as: push