Class: Sequence
- Inherits:
-
Object
- Object
- Sequence
- Defined in:
- lib/superdupe/sequence.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#current_value ⇒ Object
readonly
Returns the value of attribute current_value.
Instance Method Summary collapse
-
#initialize(starting_at = 1, sequencer = nil) ⇒ Sequence
constructor
A new instance of Sequence.
- #next ⇒ Object
Constructor Details
#initialize(starting_at = 1, sequencer = nil) ⇒ Sequence
Returns a new instance of Sequence.
4 5 6 7 8 9 10 |
# File 'lib/superdupe/sequence.rb', line 4 def initialize(starting_at=1, sequencer=nil) @current_value = starting_at if sequencer && sequencer.arity != 1 raise ArgumentError, "Your block must accept a single parameter" end @transformer = sequencer end |
Instance Attribute Details
#current_value ⇒ Object (readonly)
Returns the value of attribute current_value.
2 3 4 |
# File 'lib/superdupe/sequence.rb', line 2 def current_value @current_value end |
Instance Method Details
#next ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/superdupe/sequence.rb', line 12 def next @current_value += 1 if @transformer @transformer.call(@current_value - 1) else @current_value - 1 end end |