Class: Sidekiq::RingBuffer
- Inherits:
-
Object
- Object
- Sidekiq::RingBuffer
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/sidekiq/ring_buffer.rb
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #buffer ⇒ Object
-
#initialize(size, default = 0) ⇒ RingBuffer
constructor
A new instance of RingBuffer.
- #reset(default = 0) ⇒ Object
Constructor Details
#initialize(size, default = 0) ⇒ RingBuffer
Returns a new instance of RingBuffer.
11 12 13 14 15 |
# File 'lib/sidekiq/ring_buffer.rb', line 11 def initialize(size, default = 0) @size = size @buf = Array.new(size, default) @index = 0 end |
Instance Method Details
#<<(element) ⇒ Object
17 18 19 20 21 |
# File 'lib/sidekiq/ring_buffer.rb', line 17 def <<(element) @buf[@index % @size] = element @index += 1 element end |
#buffer ⇒ Object
23 24 25 |
# File 'lib/sidekiq/ring_buffer.rb', line 23 def buffer @buf end |
#reset(default = 0) ⇒ Object
27 28 29 |
# File 'lib/sidekiq/ring_buffer.rb', line 27 def reset(default = 0) @buf.fill(default) end |