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.



41
42
43
# File 'lib/ctioga2/graphics/styles/carrays.rb', line 41

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



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