Class: Memoizable::MethodBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/memoizable/method_builder.rb

Overview

Build the memoized method

Defined Under Namespace

Classes: BlockNotAllowedError, InvalidArityError

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • descendant (Module)
  • method_name (Symbol)
  • freezer (#call)


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_methodUnboundMethod (readonly)

The original method before memoization

Returns:

  • (UnboundMethod)


44
45
46
# File 'lib/memoizable/method_builder.rb', line 44

def original_method
  @original_method
end

Instance Method Details

#callMethodBuilder

Build a new memoized method

Examples:

method_builder.call  # => creates new method

Returns:



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