Class: MutualRecursion::TailCall
- Inherits:
-
Object
- Object
- MutualRecursion::TailCall
- Defined in:
- lib/mutual_recursion.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value = nil, &block) ⇒ TailCall
constructor
A new instance of TailCall.
-
#invoke ⇒ Object
Invoke this tail call.
Constructor Details
#initialize(value = nil, &block) ⇒ TailCall
Returns a new instance of TailCall.
7 8 9 10 |
# File 'lib/mutual_recursion.rb', line 7 def initialize(value = nil, &block) @value = value @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/mutual_recursion.rb', line 5 def block @block end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/mutual_recursion.rb', line 5 def value @value end |
Instance Method Details
#invoke ⇒ Object
Invoke this tail call. Only the returned value from the initial call to the recursive function should be invoked.
18 19 20 21 22 23 24 25 26 27 |
# 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 |