From: Robert Klemme Date: 2007-01-05T19:05:05+09:00 Subject: Re: How can I do this better? On 05.01.2007 10:30, Jean Helou wrote: > actually this seems to work too : > def foo(1) You want "def foo(i)" here. > @cache[i]||=some_method_that_takes_long_time(i) > end That's what I'd do. And then there is also memoize, which implements this pattern: http://raa.ruby-lang.org/project/memoize/ Kind regards robert