Class: CTioga2::Graphics::Styles::CircularArray

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(set) ⇒ CircularArray

Returns a new instance of CircularArray.



34
35
36
# File 'lib/ctioga2/graphics/styles/carrays.rb', line 34

def initialize(set)
  @set = set
end

Instance Attribute Details

#setObject

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

#nextObject

Returns the next element in the array



39
40
41
42
43
44
45
46
47
# File 'lib/ctioga2/graphics/styles/carrays.rb', line 39

def next
  @value ||= 0
  if @value >= @set.size
    @value = 0
  end
  val = @set[@value]
  @value += 1
  return val
end