Class: Sidekiq::RingBuffer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/sidekiq/util.rb

Overview

This module is part of Sidekiq core and not intended for extensions.

Instance Method Summary collapse

Constructor Details

#initialize(size, default = 0) ⇒ RingBuffer

Returns a new instance of RingBuffer.



18
19
20
21
22
# File 'lib/sidekiq/util.rb', line 18

def initialize(size, default = 0)
  @size = size
  @buf = Array.new(size, default)
  @index = 0
end

Instance Method Details

#<<(element) ⇒ Object



24
25
26
27
28
# File 'lib/sidekiq/util.rb', line 24

def <<(element)
  @buf[@index % @size] = element
  @index += 1
  element
end

#bufferObject



30
31
32
# File 'lib/sidekiq/util.rb', line 30

def buffer
  @buf
end

#reset(default = 0) ⇒ Object



34
35
36
# File 'lib/sidekiq/util.rb', line 34

def reset(default = 0)
  @buf.fill(default)
end