Module: TCOMethod::Mixin
- Defined in:
- lib/tco_method/mixin.rb
Overview
Mixin providing tail call optimization eval and class annotations. When extended by a Class or Module adds methods for evaluating code with tail call optimization enabled and re-evaluating existing methods with tail call optimization enabled.
Instance Method Summary collapse
-
#tco_eval(code) ⇒ Object
Evaluate the given code String with tail call optimization enabled.
-
#tco_method(method_name) ⇒ Symbol
Class annotation causing the instance method identified by the given method name to be reevaluated with tail call optimization enabled.
-
#tco_module_method(method_name) ⇒ Symbol
(also: #tco_class_method)
Module or Class annotation causing the class or module method identified by the given method name to be reevaluated with tail call optimization enabled.
-
#with_tco(&block) ⇒ Object
Allows for executing a block of code with tail call optimization enabled.
Instance Method Details
#tco_eval(code) ⇒ Object
Evaluate the given code String with tail call optimization enabled.
30 31 32 |
# File 'lib/tco_method/mixin.rb', line 30 def tco_eval(code) TCOMethod.tco_eval(code) end |
#tco_method(method_name) ⇒ Symbol
Class annotation causing the instance method identified by the given method name to be reevaluated with tail call optimization enabled. Only works for methods defined using the ‘def` keyword.
42 43 44 |
# File 'lib/tco_method/mixin.rb', line 42 def tco_method(method_name) MethodReevaluator.new(self, method_name, :instance) end |
#tco_module_method(method_name) ⇒ Symbol Also known as: tco_class_method
Module or Class annotation causing the class or module method identified by the given method name to be reevaluated with tail call optimization enabled. Only works for methods defined using the ‘def` keyword.
17 18 19 |
# File 'lib/tco_method/mixin.rb', line 17 def tco_module_method(method_name) MethodReevaluator.new(self, method_name, :module) end |
#with_tco(&block) ⇒ Object
Allows for executing a block of code with tail call optimization enabled.
All code that is evaluated in the block will be evaluated with tail call optimization enabled, however here be dragons, so make sure to read the docs for TCOMethod.with_tco before getting too crazy.
56 57 58 |
# File 'lib/tco_method/mixin.rb', line 56 def with_tco(&block) TCOMethod.with_tco(&block) end |