Sha256: ad825aa4a147e04742341594416ddd5b3eb15a68bffbea6881544777413ae547
Contents?: true
Size: 795 Bytes
Versions: 55
Compression:
Stored size: 795 Bytes
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Collections #:nodoc: class CyclicIterator attr_reader :counter # Performs iteration over an array, if the array gets to the end then loop # back to the first. # # Example: # # <tt>CyclicIterator.new([ first, second ])</tt> def initialize(array) @array, @counter = array, -1 end # Get the next element in the array. If the element is the last in the # array then return the first. # # Example: # # <tt>iterator.next</tt> # # Returns: # # The next element in the array. def next (@counter == @array.size - 1) ? @counter = 0 : @counter = @counter + 1 @array[@counter] end end end end
Version data entries
55 entries across 55 versions & 8 rubygems