Class: Datadog::Core::Utils::Sequence
- Inherits:
-
Object
- Object
- Datadog::Core::Utils::Sequence
- Defined in:
- lib/datadog/core/utils/sequence.rb
Overview
Generates values from a consistent sequence
Instance Method Summary collapse
-
#initialize(seed = 0, &block) ⇒ Sequence
constructor
A new instance of Sequence.
- #next ⇒ Object
- #reset! ⇒ Object
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
#next ⇒ Object
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 |