Module: FondMemos

Defined in:
lib/fond_memos.rb,
lib/fond_memos/version.rb

Overview

foo = Foo.new foo.bar # expensive foo.bar # fast foo.forget(:bar) foo.bar # expensive again (why did you forget?) foo.bar # fast again (that’s better)

If you memoize a method with arguments, the #hash method will be called on each argument to generate a key to use in FondMemo’s internal hash. To ensure safe and responsible memoizing, it is strongly encouraged to ensure your memoized method arguments have logical hash values.

May you always have fond memos of using this gem!

Defined Under Namespace

Modules: ClassMethods, Internal

Constant Summary collapse

VERSION =
'0.1.0'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



32
33
34
# File 'lib/fond_memos.rb', line 32

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#forget(method) ⇒ Object

Calling this will remove the caching instance variable for the method. In the case of multi argument methods, all values will be forgotten.

Parameters:

  • method (Symbol)

    the method to forget



39
40
41
# File 'lib/fond_memos.rb', line 39

def forget(method)
  remove_instance_variable(Internal.var_name(method))
end