class CTioga2::Graphics::Styles::CircularArray
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').
Attributes
set[R]
The set through which we go
Public Class Methods
new(set)
click to toggle source
# File lib/ctioga2/graphics/styles/carrays.rb, line 39 def initialize(set) @set = set end
Public Instance Methods
next()
click to toggle source
Returns the next element in the array
# 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
set=(s)
click to toggle source
Defines the set of elements we'll be circling through and resets the index.
# File lib/ctioga2/graphics/styles/carrays.rb, line 34 def set=(s) @set = s @value = 0 end