Module: Lite::Memoize::Alias::InstanceMethods

Defined in:
lib/lite/memoize/alias.rb

Instance Method Summary collapse

Instance Method Details

#clear_cache(*method_names) ⇒ Object Also known as: clear, flush_cache



29
30
31
32
33
34
35
# File 'lib/lite/memoize/alias.rb', line 29

def clear_cache(*method_names)
  memoized_structs(method_names).each do |struct|
    next unless instance_variable_defined?(struct.ivar)

    remove_instance_variable(struct.ivar)
  end
end

#memoize_all(*method_names) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/lite/memoize/alias.rb', line 19

def memoize_all(*method_names)
  memoized_structs(method_names).each do |struct|
    if struct.arity.zero?
      __send__(struct.memoized_method)
    else
      instance_variable_set(struct.ivar, {})
    end
  end
end

#memoized_structs(names) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/lite/memoize/alias.rb', line 11

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