module FondMemos::ClassMethods

Public Instance Methods

memoize(*methods) click to toggle source

Add memoization for the listed methods @param methods [Array<Symbol>] the methods to memoize

# 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