From: matt@... (matt neuburg) Date: 2008-10-14T07:02:59+09:00 Subject: Re: status of cache in Memoizable James Gray wrote: > On Oct 13, 2008, at 2:17 PM, matt neuburg wrote: > > > 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? > > That variable is kept alive thanks to the magic of closures. The block > passed to define_method() references the variable, so it will exist as > long as that closure does. Think of it as private storage that only > that block uses. Great answer, thanks! m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Leopard - http://www.takecontrolbooks.com/leopard-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com