From: Robert Klemme Date: 2007-01-08T20:15:08+09:00 Subject: Re: a most undangerous Hash#store! On 08.01.2007 02:00, dblack@wobblini.net wrote: > Hi -- > > On Mon, 8 Jan 2007, Trans wrote: > >> >> Daniel Schierbeck wrote: >> >>> Is there really a need for such a method? Why not simply: >>> >>> hsh[:key] ||= "value" >> >> This isn't quite the same becasue it looks to see if tha value is nil >> or false, not if the key is there or not. >> >>> or, if you have a default value on your hash: >>> >>> hsh[:key] = "value" unless hsh.has_key? :key >> >> Yes, certianly. nad that woul dbe fine if I were just needing here and >> ther, but I have need for using it quite often. > > You can use merge and a one-key hash: > > hash.merge({ :key => "new value" }) Or even hash.merge( :key => "new value" ) robert