Class: Memoizable::MethodBuilder
- Inherits:
-
Object
- Object
- Memoizable::MethodBuilder
- Defined in:
- lib/memoizable/method_builder.rb
Overview
Build the memoized method
Defined Under Namespace
Classes: BlockNotAllowedError, InvalidArityError
Instance Attribute Summary collapse
-
#original_method ⇒ UnboundMethod
readonly
The original method before memoization.
Instance Method Summary collapse
-
#call ⇒ MethodBuilder
Build a new memoized method.
-
#initialize(descendant, method_name, freezer) ⇒ undefined
constructor
private
Initialize an object to build a memoized method.
Constructor Details
#initialize(descendant, method_name, freezer) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize an object to build a memoized method
55 56 57 58 59 60 61 62 |
# File 'lib/memoizable/method_builder.rb', line 55 def initialize(descendant, method_name, freezer) @descendant = descendant @method_name = method_name @freezer = freezer @original_visibility = visibility @original_method = @descendant.instance_method(@method_name) assert_arity(@original_method.arity) end |
Instance Attribute Details
#original_method ⇒ UnboundMethod (readonly)
The original method before memoization
44 45 46 |
# File 'lib/memoizable/method_builder.rb', line 44 def original_method @original_method end |
Instance Method Details
#call ⇒ MethodBuilder
Build a new memoized method
72 73 74 75 76 77 |
# File 'lib/memoizable/method_builder.rb', line 72 def call remove_original_method create_memoized_method set_method_visibility self end |