Sha256: a31d5e14d56886752adcaa5982692e38a50bbc5c17dc0d750dbc60efcb2e3c83

Contents?: true

Size: 1.52 KB

Versions: 10

Compression:

Stored size: 1.52 KB

Contents

# carrays.rb: 'circular arrays'
# copyright (c) 2009 by Vincent Fourmond
  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
  
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details (in the COPYING file).

require 'ctioga2/utils'
require 'ctioga2/log'

# This module contains all the classes used by ctioga
module CTioga2

  module Graphics

    module Styles

      # 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').
      class CircularArray
        
        # The set through which we go
        attr_reader :set

        # Defines the set of elements we'll be circling through and
        # resets the index.
        def set=(s)
          @set = s
          @value = 0
        end
        
        def initialize(set)
          @set = set
        end

        # Returns the next element in the array
        def next
          @value ||= 0
          if @value >= @set.size
            @value = 0
          end
          val = @set[@value]
          @value += 1
          return val
        end
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ctioga2-0.14.1 lib/ctioga2/graphics/styles/carrays.rb
ctioga2-0.14 lib/ctioga2/graphics/styles/carrays.rb
ctioga2-0.13.1 lib/ctioga2/graphics/styles/carrays.rb
ctioga2-0.13 lib/ctioga2/graphics/styles/carrays.rb
ctioga2-0.12 lib/ctioga2/graphics/styles/carrays.rb
ctioga2-0.11 lib/ctioga2/graphics/styles/carrays.rb
ctioga2-0.10.1 lib/ctioga2/graphics/styles/carrays.rb
ctioga2-0.10 lib/ctioga2/graphics/styles/carrays.rb
ctioga2-0.9 lib/ctioga2/graphics/styles/carrays.rb
ctioga2-0.8 lib/ctioga2/graphics/styles/carrays.rb