From: Thomas Hafner Date: 2009-05-04T23:40:05+09:00 Subject: Re: lazy lookup Robert Klemme wrote/schrieb <763388F1amqkuU1@mid.individual.net>: > Sorry to sound discouraging but there is memoize already. The > difference is that not the whole Hash is filled but only the one > that you need for the argument list provided which seems potentially > more efficient. In my situation this ist not the case. The key value pairs can be retrieved by reading a file. It's better to open/read/close the file only once and retrieve all key value pairs at the same time. Of course the file should not be read at all, if never a value will be requested. > In case you want to fill the Hash completely you can just replace the > calculation code to assign multiple values. How does that look like? Somethink like that?: Hash.new{ |h,k| h.replace( COMPLETELY_CALCULATED_HASH ); h[k] } (COMPLETELY_CALCULATED_HASH should be replaced by some code which calculates the hash completely) Regards Thomas