Class: MTK::Patterns::Cycle

Inherits:
Sequence show all
Defined in:
lib/mtk/patterns/cycle.rb

Overview

An endless enumerator that outputs an element one at a time from a list of elements, looping back to the beginning when elements run out. This is the same as a Sequence but by default has unlimited @max_cycles

Direct Known Subclasses

Palindrome

Instance Attribute Summary

Attributes inherited from Pattern

#cycle_count, #element_count, #elements, #max_cycles, #max_elements, #min_elements, #options

Instance Method Summary collapse

Methods inherited from Sequence

#advance

Methods inherited from Pattern

#advance, #empty?, from_a, #max_cycles_exceeded?, #max_elements_exceeded?, #min_elements_unmet?, #next, #rewind, #rewind_or_cycle

Methods included from Groups::Collection

#==, #[], #clone, #concat, #each, #empty?, #enumerable_map, #first, #last, #map, #partition, #permute, #repeat, #reverse, #rotate, #size, #to_a

Constructor Details

#initialize(elements, options = {}) ⇒ Cycle

Returns a new instance of Cycle.



9
10
11
12
13
# File 'lib/mtk/patterns/cycle.rb', line 9

def initialize(elements, options={})
  super
  # Base Pattern & Sequence default to 1 max_cycle, this defaults to nil which is unlimited cycles
  @max_cycles = options[:max_cycles]
end