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.
41 42 43 |
# File 'lib/ctioga2/graphics/styles/carrays.rb', line 41 def initialize(set) @set = set end |
Instance Attribute Details
#set ⇒ Object
The set through which we go
32 33 34 |
# File 'lib/ctioga2/graphics/styles/carrays.rb', line 32 def set @set end |
Instance Method Details
#next ⇒ Object
Returns the next element in the array
46 47 48 49 50 51 52 53 54 |
# File 'lib/ctioga2/graphics/styles/carrays.rb', line 46 def next @value ||= 0 if @value >= @set.size @value = 0 end val = @set[@value] @value += 1 return val end |