lib/memoit.rb in memoit-0.1.1 vs lib/memoit.rb in memoit-0.1.2

- old
+ new

@@ -14,10 +14,15 @@ ivar_name = "@_memo_#{name}".to_sym mod = Module.new do define_method(name) do |*args, &block| return super(*args, &block) if block cache = instance_variable_get(ivar_name) || instance_variable_set(ivar_name, {}) - cache[args.hash] ||= super(*args) + hash = args.hash + if cache.has_key?(hash) + cache[hash] + else + cache[hash] = super(*args) + end end end prepend mod end end