Class: Usine::Sequence
- Inherits:
-
Object
- Object
- Usine::Sequence
- Defined in:
- lib/usine/sequence.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
Instance Method Summary collapse
-
#initialize(attribute, *args, &block) ⇒ Sequence
constructor
A new instance of Sequence.
- #next ⇒ Object
Constructor Details
#initialize(attribute, *args, &block) ⇒ Sequence
Returns a new instance of Sequence.
5 6 7 8 9 10 11 12 13 |
# File 'lib/usine/sequence.rb', line 5 def initialize(attribute, *args, &block) @attribute = attribute @block = block @value = args.first || 1 unless @value.respond_to?(:next) raise(UsineError::SequenceInvalidInitialValue, "Invalid initial value, it must respond to #next") end end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
3 4 5 |
# File 'lib/usine/sequence.rb', line 3 def attribute @attribute end |
Instance Method Details
#next ⇒ Object
15 16 17 18 19 |
# File 'lib/usine/sequence.rb', line 15 def next @block.call(@value) ensure @value = @value.next end |