Class: Fulmar::RingBuffer
- Inherits:
-
Array
- Object
- Array
- Fulmar::RingBuffer
- Defined in:
- lib/fulmar/ringbuffer.rb
Instance Attribute Summary collapse
-
#max_size ⇒ Object
readonly
Returns the value of attribute max_size.
Instance Method Summary collapse
- #<<(el) ⇒ Object (also: #push)
-
#initialize(max_size, enum = nil) ⇒ RingBuffer
constructor
A new instance of RingBuffer.
Constructor Details
#initialize(max_size, enum = nil) ⇒ RingBuffer
Returns a new instance of RingBuffer.
5 6 7 8 |
# File 'lib/fulmar/ringbuffer.rb', line 5 def initialize(max_size, enum = nil) @max_size = max_size enum.each { |e| self << e } if enum end |
Instance Attribute Details
#max_size ⇒ Object (readonly)
Returns the value of attribute max_size.
3 4 5 |
# File 'lib/fulmar/ringbuffer.rb', line 3 def max_size @max_size end |
Instance Method Details
#<<(el) ⇒ Object Also known as: push
10 11 12 13 14 15 16 17 |
# File 'lib/fulmar/ringbuffer.rb', line 10 def <<(el) if self.size < @max_size || @max_size.nil? super else self.shift self.push(el) end end |