Class: CTioga2::Graphics::Styles::CircularArray
- Inherits:
-
Object
- Object
- CTioga2::Graphics::Styles::CircularArray
- Defined in:
- lib/ctioga2/graphics/styles/carrays.rb
Overview
A CirularArray, i.e an array from which one can extract successive elements in a fixed order, and that turns back to the first element once all have been used (hence ‘circular’).
Instance Attribute Summary collapse
-
#set ⇒ Object
The set through which we go.
Instance Method Summary collapse
-
#initialize(set) ⇒ CircularArray
constructor
A new instance of CircularArray.
-
#next ⇒ Object
Returns the next element in the array.
Constructor Details
#initialize(set) ⇒ CircularArray
Returns a new instance of CircularArray.
39 40 41 |
# File 'lib/ctioga2/graphics/styles/carrays.rb', line 39 def initialize(set) @set = set end |
Instance Attribute Details
#set ⇒ Object
The set through which we go
30 31 32 |
# File 'lib/ctioga2/graphics/styles/carrays.rb', line 30 def set @set end |
Instance Method Details
#next ⇒ Object
Returns the next element in the array
44 45 46 47 48 49 50 51 52 |
# File 'lib/ctioga2/graphics/styles/carrays.rb', line 44 def next @value ||= 0 if @value >= @set.size @value = 0 end val = @set[@value] @value += 1 return val end |