Module: Philiprehberger::Memo::Wrapper

Defined in:
lib/philiprehberger/memo/wrapper.rb

Overview

Wraps methods with memoization via define_method

Class Method Summary collapse

Class Method Details

.apply(klass, method_name, ttl:, max_size:) ⇒ Object

Apply memoization to a method

Parameters:

  • klass (Class)

    the target class

  • method_name (Symbol)

    the method to wrap

  • ttl (Numeric, nil)

    cache TTL

  • max_size (Integer, nil)

    max cache entries



13
14
15
16
17
18
# File 'lib/philiprehberger/memo/wrapper.rb', line 13

def self.apply(klass, method_name, ttl:, max_size:)
  original = klass.instance_method(method_name)
  opts = { ttl: ttl, max_size: max_size }

  define_memoized_method(klass, method_name, original, opts)
end