Class: Dexc::RingBuffer
- Inherits:
-
Object
- Object
- Dexc::RingBuffer
- Defined in:
- lib/dexc.rb
Instance Method Summary collapse
- #add(val) ⇒ Object
-
#initialize(n) ⇒ RingBuffer
constructor
A new instance of RingBuffer.
- #to_a ⇒ Object
Constructor Details
#initialize(n) ⇒ RingBuffer
Returns a new instance of RingBuffer.
16 17 18 19 20 |
# File 'lib/dexc.rb', line 16 def initialize(n) @n = n @buf = [] @idx = 0 end |
Instance Method Details
#add(val) ⇒ Object
22 23 24 25 |
# File 'lib/dexc.rb', line 22 def add(val) @buf[@idx] = val @idx = (@idx + 1) % @n end |
#to_a ⇒ Object
27 28 29 |
# File 'lib/dexc.rb', line 27 def to_a @buf[@idx..-1] + @buf[0...@idx] end |