class MTK::Patterns::Function

An arbitrary function that dynamically generates elements.

Attributes

function[R]

Public Class Methods

new(elements, options={}) click to toggle source
Calls superclass method
# File lib/mtk/patterns/function.rb, line 10
def initialize(elements, options={})
  # unpack from the varargs Array that may be passed in from the "convenience constructor methods" defined in MTK::Pattern                        \
  @function = if elements.is_a? Enumerable then elements.first else elements end
  super [@function], options
end

Protected Instance Methods

advance() click to toggle source
# File lib/mtk/patterns/function.rb, line 26
def advance
  @function_call_count += 1
  @current = case @function.arity
    when 0 then @function.call
    when 1 then @function.call(@current)
    when 2 then @function.call(@current, @function_call_count)
    else @function.call(@current, @function_call_count, @element_count)
  end
end
rewind_or_cycle(is_cycling=false) click to toggle source

(see Pattern#rewind_or_cycle)

Calls superclass method
# File lib/mtk/patterns/function.rb, line 21
def rewind_or_cycle(is_cycling=false)
  @function_call_count = -1
  super
end