Class: Datadog::Core::Utils::Sequence

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/utils/sequence.rb

Overview

Generates values from a consistent sequence

Instance Method Summary collapse

Constructor Details

#initialize(seed = 0, &block) ⇒ Sequence

Returns a new instance of Sequence.



8
9
10
11
12
# File 'lib/datadog/core/utils/sequence.rb', line 8

def initialize(seed = 0, &block)
  @seed = seed
  @current = seed
  @next_item = block
end

Instance Method Details

#nextObject



14
15
16
17
18
# File 'lib/datadog/core/utils/sequence.rb', line 14

def next
  next_item = @next_item ? @next_item.call(@current) : @current
  @current += 1
  next_item
end

#reset!Object



20
21
22
# File 'lib/datadog/core/utils/sequence.rb', line 20

def reset!
  @current = @seed
end