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.



39
40
41
# File 'lib/ctioga2/graphics/styles/carrays.rb', line 39

def initialize(set)
  @set = set
end

Instance Attribute Details

#setObject

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

#nextObject

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