From: nobu.nokada@... Date: 2001-12-23T12:44:16+09:00 Subject: [ruby-talk:29344] Re: a better way? At Sun, 23 Dec 2001 10:43:41 +0900, David Alan Black wrote: > I think the design is that some calculation will only be performed > once, then cached -- one of these guys: Another one using Hash#fetch, class Temp @@save = {} def fahrenheit(c) @@save.fetch(c) do puts "Performing calculation...." @@save[c] = c * 9 / 5 + 32 end end end Or in recent 1.7.2, class Temp @@save = Hash.new do |h, c| puts "Performing calculation...." h[c] = c * 9 / 5 + 32 end def fahrenheit(c) @@save[c] end end Nobu Nakada