module Memoist::InstanceMethods

def flush_cache(*method_names)

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

def memoize_all

def memoize_all
  prime_cache
end

def memoized_structs(names)

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

def prime_cache(*method_names)

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

def unmemoize_all

def unmemoize_all
  flush_cache
end