From: Pit Capitain Date: 2005-10-18T05:30:48+09:00 Subject: Re: declaratively caching results of a method Brian Buckley schrieb: > How can one, for example, access > the cache to see the state of the cache? See below: > module Memoize > MEMOIZE_VERSION = "1.0.0" > def memoize(name) > meth = method(name) > cache = {} > (class << self; self; end).class_eval do > define_method(name) do |*args| > cache[args] ||= meth.call(*args) > end define_method("#{name}_cache") do cache end > end > end > end Untested, but should work. Regards, Pit