From: Chuck Remes Date: 2008-10-14T04:33:37+09:00 Subject: Re: status of cache in Memoizable On Oct 13, 2008, at 2:17 PM, matt neuburg wrote: > [snip] > > [The actual question:] > > There's one thing happening here I don't understand. Let's say you > don't > supply a value for the "cache" parameter. So the cache is simply > Hash.new. But where does this Hash.new live? It isn't assigned to a > variable name so what keeps it alive? It works, but how? This line here keeps the reference to cache alive: define_method(name) { |*args| cache[args] ||= send(original, *args) } This is defining a new method and knows to return the cached value or send the arguments to the original unmemoized method so it can compute your value. cr