lib/nanoc3/base/memoization.rb in nanoc3-3.2.0a4 vs lib/nanoc3/base/memoization.rb in nanoc3-3.2.0b1

- old
+ new

@@ -47,24 +47,21 @@ original_method_name = '__nonmemoized_' + method_name.to_s alias_method original_method_name, method_name # Redefine define_method(method_name) do |*args| - # Get method-specific cache - key = [ self, method_name ] - if !CACHE.has_key?(key) - CACHE[key] = {} - end - method_cache = CACHE[key] + # Get cache + @cache ||= {} + @cache[method_name] ||= {} # Recalculate if necessary - if !method_cache.has_key?(args) + if !@cache[method_name].has_key?(args) result = send(original_method_name, *args) - method_cache[args] = result + @cache[method_name][args] = result end # Done - method_cache[args] + @cache[method_name][args] end end end