Module: AIXM::Concerns::Memoize
- Defined in:
- lib/aixm/concerns/memoize.rb
Overview
Memoize the return value of a specific method across multiple instances for the duration of a block.
The method signature is taken into account, therefore calls of the same method with different positional and/or keyword arguments are cached independently. On the other hand, when calling the method with a block, no memoization is performed at all.
Nested memoization of the same method is allowed and won’t reset the memoization cache.
Defined Under Namespace
Modules: ClassMethods
Class Attribute Summary collapse
-
.cache ⇒ Object
readonly
Returns the value of attribute cache.
Class Method Summary collapse
- .included(base) ⇒ Object
-
.method(method, &block) ⇒ Object
TODO: [ruby-3.1] use anonymous block “&” on this and next line.
Class Attribute Details
.cache ⇒ Object (readonly)
Returns the value of attribute cache.
77 78 79 |
# File 'lib/aixm/concerns/memoize.rb', line 77 def cache @cache end |
Class Method Details
.included(base) ⇒ Object
79 80 81 82 |
# File 'lib/aixm/concerns/memoize.rb', line 79 def included(base) base.extend(ClassMethods) @cache = {} end |
.method(method, &block) ⇒ Object
TODO: [ruby-3.1] use anonymous block “&” on this and next line
84 85 86 |
# File 'lib/aixm/concerns/memoize.rb', line 84 def method(method, &block) # TODO: [ruby-3.1] use anonymous block "&" on this and next line send(:"call_with#{:out if cached?(method)}_cache", method, &block) end |