module Memoist::InstanceMethods

Public Instance Methods

flush_cache(*method_names) click to toggle source
# File lib/memoist.rb, line 95
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() click to toggle source
# File lib/memoist.rb, line 69
def memoize_all
  prime_cache
end
memoized_structs(names) click to toggle source
# File lib/memoist.rb, line 77
def memoized_structs(names)
  ref_obj = self.class.respond_to?(:class_eval) ? singleton_class : self
  structs = ref_obj.all_memoized_structs
  return structs if names.empty?

  structs.select { |s| names.include?(s.memoized_method) }
end
prime_cache(*method_names) click to toggle source
# File lib/memoist.rb, line 85
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() click to toggle source
# File lib/memoist.rb, line 73
def unmemoize_all
  flush_cache
end