Class: TCOMethod::MethodReevaluator
- Inherits:
-
Object
- Object
- TCOMethod::MethodReevaluator
- Defined in:
- lib/tco_method/method_reevaluator.rb
Instance Method Summary collapse
-
#initialize(receiver, method_name, method_owner) ⇒ MethodReevaluator
constructor
Reevaluates a method with tail call optimization enabled.
Constructor Details
#initialize(receiver, method_name, method_owner) ⇒ MethodReevaluator
Note:
This class is not part of the public API and should not be used directly. See TCOMethod::Mixin for a module that provides publicly supported access to the behaviors provided by this method.
Reevaluates a method with tail call optimization enabled.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tco_method/method_reevaluator.rb', line 21 def initialize(receiver, method_name, method_owner) raise ArgumentError, "Receiver required!" unless receiver raise ArgumentError, "Method name required!" unless method_name raise ArgumentError, "Method owner required!" unless method_owner if method_owner == :instance existing_method = receiver.instance_method(method_name) elsif method_owner == :class || method_owner== :module existing_method = receiver.method(method_name) end method_info = MethodInfo.new(existing_method) if method_info.type != :method raise TypeError, "Invalid method type: #{method_info.type}" end receiver_class = receiver.is_a?(Class) ? :class : :module code = <<-CODE #{receiver_class} #{receiver.name} #{existing_method.source} end CODE file, line = existing_method.source_location TCOMethod.tco_eval(code, file, File.dirname(file), line - 1) end |