Module: Memoist::InstanceMethods
- Defined in:
- lib/memoist.rb
Instance Method Summary collapse
- #flush_cache(*method_names) ⇒ Object
- #memoize_all ⇒ Object
- #memoized_structs(names) ⇒ Object
- #prime_cache(*method_names) ⇒ Object
- #unmemoize_all ⇒ Object
Instance Method Details
#flush_cache(*method_names) ⇒ Object
85 86 87 88 89 |
# File 'lib/memoist.rb', line 85 def flush_cache(*method_names) memoized_structs(method_names).each do |struct| remove_instance_variable(struct.ivar) if instance_variable_defined?(struct.ivar) end end |
#memoize_all ⇒ Object
60 61 62 |
# File 'lib/memoist.rb', line 60 def memoize_all prime_cache end |
#memoized_structs(names) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/memoist.rb', line 68 def memoized_structs(names) structs = self.class.all_memoized_structs return structs if names.empty? structs.select { |s| names.include?(s.memoized_method) } end |
#prime_cache(*method_names) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/memoist.rb', line 75 def prime_cache(*method_names) memoized_structs(method_names).each do |struct| if struct.arity == 0 __send__(struct.memoized_method) else instance_variable_set(struct.ivar, {}) end end end |
#unmemoize_all ⇒ Object
64 65 66 |
# File 'lib/memoist.rb', line 64 def unmemoize_all flush_cache end |