From: Joel VanderWerf Date: 2007-01-14T17:36:43+09:00 Subject: Re: return_on Gavin Sinclair wrote: > On Jan 14, 1:34 am, "Trans" wrote: >> def x >> return_on @cache[:x] >> # do stuff >> @cache[:x] = result_of_stuff >> end >> > > def x > @cache[:x] ||= begin > # do stuff > end > end Or (saving an exception handler setup): def reverse x @cache[:x] ||= ( puts "CACHING" x.reverse ) end @cache = {} p reverse("foo") p reverse("foo") __END__ Output: CACHING "oof" "oof" -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407