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, **options) ⇒ Mixin
Creates or retrieves a memoization mixin for the given methods and options.
Instance Method Summary collapse
-
#add_keywords? ⇒ Boolean
Whether constructor keywords can prefill the cache.
-
#reset_copy? ⇒ Boolean
Whether copies get fresh memoization atoms.
-
#weak? ⇒ Boolean
Whether the memoization is weak.
Instance Attribute Details
#memoized_methods ⇒ Array<Symbol> (readonly)
Returns the memoized methods.
149 150 151 |
# File 'lib/farce/memoize.rb', line 149 def memoized_methods @memoized_methods end |
#mode ⇒ Symbol? (readonly)
Returns the transfer mode, or nil for a scoped cache.
155 156 157 |
# File 'lib/farce/memoize.rb', line 155 def mode @mode end |
#scope ⇒ Symbol (readonly)
Returns the scope of the memoization.
152 153 154 |
# File 'lib/farce/memoize.rb', line 152 def scope @scope end |
#visibility ⇒ Symbol (readonly)
Returns the visibility of the memoized methods.
158 159 160 |
# File 'lib/farce/memoize.rb', line 158 def visibility @visibility end |
Class Method Details
.new(*methods, **options) ⇒ Mixin
Creates or retrieves a memoization mixin for the given methods and options.
120 121 122 123 124 125 126 |
# File 'lib/farce/memoize.rb', line 120 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
#add_keywords? ⇒ Boolean
Returns whether constructor keywords can prefill the cache.
262 |
# File 'lib/farce/memoize.rb', line 262 def add_keywords? = @add_keywords |
#reset_copy? ⇒ Boolean
Returns whether copies get fresh memoization atoms.
259 |
# File 'lib/farce/memoize.rb', line 259 def reset_copy? = @reset_copy |
#weak? ⇒ Boolean
Returns whether the memoization is weak.
256 |
# File 'lib/farce/memoize.rb', line 256 def weak? = @weak |