Module: FondMemos::ClassMethods

Defined in:
lib/fond_memos.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#memoize(*methods) ⇒ Object

Add memoization for the listed methods

Parameters:

  • methods (Array<Symbol>)

    the methods to memoize



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fond_memos.rb', line 65

def memoize(*methods)
  methods.each do |m|
    original_method = instance_method(m)
    var_name = Internal.var_name(original_method.name)
    undef_method(m)
    if original_method.arity.zero?
      define_method(m) { _fond_fetch(var_name, original_method) }
    else
      define_method(m) { |*args| _fond_multi_fetch(var_name, original_method, args) }
    end
  end
end