Class: Farce::Memoize::Mixin
- Inherits:
-
Module
- Object
- Module
- Farce::Memoize::Mixin
- Defined in:
- lib/farce/memoize.rb
Overview
Mixins used to implement memoization for different methods, scopes, and modes
Instance Attribute Summary collapse
-
#memoized_methods ⇒ Array<Symbol>
readonly
The memoized methods.
-
#mode ⇒ Symbol?
readonly
The transfer mode, or nil for a scoped cache.
-
#scope ⇒ Symbol
readonly
The scope of the memoization.
-
#visibility ⇒ Symbol
readonly
The visibility of the memoized methods.
Class Method Summary collapse
-
.new(*methods, scope: :global, mode: :smart, weak: false, visibility: nil) ⇒ Mixin
Creates or retrieves a memoization mixin for the given methods and options.
Instance Method Summary collapse
-
#weak? ⇒ Boolean
Whether the memoization is weak.
Instance Attribute Details
#memoized_methods ⇒ Array<Symbol> (readonly)
Returns the memoized methods.
134 135 136 |
# File 'lib/farce/memoize.rb', line 134 def memoized_methods @memoized_methods end |
#mode ⇒ Symbol? (readonly)
Returns the transfer mode, or nil for a scoped cache.
140 141 142 |
# File 'lib/farce/memoize.rb', line 140 def mode @mode end |
#scope ⇒ Symbol (readonly)
Returns the scope of the memoization.
137 138 139 |
# File 'lib/farce/memoize.rb', line 137 def scope @scope end |
#visibility ⇒ Symbol (readonly)
Returns the visibility of the memoized methods.
143 144 145 |
# File 'lib/farce/memoize.rb', line 143 def visibility @visibility end |
Class Method Details
.new(*methods, scope: :global, mode: :smart, weak: false, visibility: nil) ⇒ Mixin
Creates or retrieves a memoization mixin for the given methods and options.
107 108 109 110 111 112 113 |
# File 'lib/farce/memoize.rb', line 107 def self.new(*methods, **) return super unless self == Mixin methods = Farce.dedup(methods.map(&:to_sym).uniq.sort) = Farce.dedup(()) map = KNOWN.store_if_absent() { Strict::Map.new } map.store_if_absent(methods) { super(methods, **) } end |
Instance Method Details
#weak? ⇒ Boolean
Returns whether the memoization is weak.
214 |
# File 'lib/farce/memoize.rb', line 214 def weak? = @weak |