Module: ActiveSupport::Memoizable::InstanceMethods
- Defined in:
- lib/active_support/memoizable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #flush_cache(*syms, &block) ⇒ Object
- #freeze_with_memoizable ⇒ Object
- #memoize_all ⇒ Object
- #prime_cache(*syms) ⇒ Object
- #unmemoize_all ⇒ Object
Class Method Details
.included(base) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/active_support/memoizable.rb', line 8 def self.included(base) base.class_eval do unless base.method_defined?(:freeze_without_memoizable) alias_method_chain :freeze, :memoizable end end end |
Instance Method Details
#flush_cache(*syms, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/active_support/memoizable.rb', line 44 def flush_cache(*syms, &block) syms.each do |sym| (methods + private_methods + protected_methods).each do |m| if m.to_s =~ /^_unmemoized_(#{sym})/ ivar = ActiveSupport::Memoizable.memoized_ivar_for($1) instance_variable_get(ivar).clear if instance_variable_defined?(ivar) end end end end |
#freeze_with_memoizable ⇒ Object
16 17 18 19 |
# File 'lib/active_support/memoizable.rb', line 16 def freeze_with_memoizable memoize_all unless frozen? freeze_without_memoizable end |
#memoize_all ⇒ Object
21 22 23 |
# File 'lib/active_support/memoizable.rb', line 21 def memoize_all prime_cache ".*" end |
#prime_cache(*syms) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/active_support/memoizable.rb', line 29 def prime_cache(*syms) syms.each do |sym| methods.each do |m| if m.to_s =~ /^_unmemoized_(#{sym})/ if method(m).arity == 0 __send__($1) else ivar = ActiveSupport::Memoizable.memoized_ivar_for($1) instance_variable_set(ivar, {}) end end end end end |
#unmemoize_all ⇒ Object
25 26 27 |
# File 'lib/active_support/memoizable.rb', line 25 def unmemoize_all flush_cache ".*" end |