Class: KnifeAdvisor::RingBuffer
- Inherits:
-
Object
- Object
- KnifeAdvisor::RingBuffer
- Defined in:
- lib/knife_advisor/ring_buffer.rb
Instance Method Summary collapse
- #advance! ⇒ Object
-
#initialize(values = []) ⇒ RingBuffer
constructor
A new instance of RingBuffer.
- #next ⇒ Object
Constructor Details
#initialize(values = []) ⇒ RingBuffer
Returns a new instance of RingBuffer.
20 21 22 23 |
# File 'lib/knife_advisor/ring_buffer.rb', line 20 def initialize(values=[]) @values = values.shuffle @i = 0 end |
Instance Method Details
#advance! ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/knife_advisor/ring_buffer.rb', line 25 def advance! @i += 1 if @i >= @values.length @i = 0 @values.shuffle! end end |
#next ⇒ Object
33 34 35 |
# File 'lib/knife_advisor/ring_buffer.rb', line 33 def next @values[@i].tap { advance! } end |