From: james@... Date: 2002-03-28T01:44:06+09:00 Subject: RE: Hash.new(Hash.new) doesn't use Hash.new as default value > > Hi, > > In message "Re: Hash.new(Hash.new) doesn't use Hash.new as default value" > on 02/03/27, ts writes: > > | With 1.7 you'll have the possibility to write > | > | Hash.new { Hash.new } > | > | and each times a key is not defined, ruby will evaluate the block, the > | result of the block will be stored in the Hash and ruby will > do what you > | want. > > It does not store the evaluated default value. Should it? Do you mean something like #----------------- 8< ------------------ h = Hash.new { |key| "There is no entry for '#{key.to_s}'" } h["here"] = "OK" puts h["missing"] # prints "There is no entry for 'missing'" h.each{ |k,v| puts "#{k} => #{v} } # prints # "here => OK" # "missing => There is no entry for 'missing'" #----------------- 8< ------------------ Might be nice to allow returning one computed default value, but storing a different computed default value. James > > matz. >