class MutualRecursion::TailCall
Attributes
block[R]
value[R]
Public Class Methods
new(value = nil, &block)
click to toggle source
# File lib/mutual_recursion.rb, line 7 def initialize(value = nil, &block) @value = value @block = block end
Public Instance Methods
invoke()
click to toggle source
Invoke this tail call. Only the returned value from the initial call to the recursive function should be invoked.
@return [Object] the terminal_value of this tail call
# File lib/mutual_recursion.rb, line 18 def invoke self.then do |tail| while tail.block tail = tail.block.call raise MissingTailCallError unless tail.is_a?(TailCall) end tail.value end end