From: Daniel Berger Date: 2005-10-21T02:01:16+09:00 Subject: Re: declaratively caching results of a method Brian Buckley wrote: >>>>Alrighty, then. I'll make that change in the next release > > . > Here's another change to memoize for your consideration: > > Suppose the result of a method call is nil or false, and suppose it > takes a lot of work to find that out. As written, methods that return > nil or false are not getting speedups from memoize. > > How about changing memoize to something like below? > > define_method(name) do |*args| > #cache[args] ||= meth.call(*args) #what if the cached value is > nil or false? > cache.has_key?(args) ? cache[args] : cache[args] ||= meth.call(*args) > end > > Brian Good idea! Thanks! Dan