On 08.01.2007 02:59, dblack / wobblini.net wrote:
> Hi --
> 
> On Mon, 8 Jan 2007, Florian Gross wrote:
> 
>> On 2007-01-08 02:00:10 +0100, dblack / wobblini.net said:
>>
>>> hsh[:key] = "value" unless hsh.has_key? :key
>>> You can use merge and a one-key hash:
>>>
>>>    hash.merge({ :key => "new value" })
>>
>> Hm, not really:
>>
>> { :key => "old value" }.merge({ :key => "new value" }) # => 
>> {:key=>"new value"}
> 
> True -- that's a bit of a deal-breaker :-)

But only if you need the return value:

irb(main):001:0> hash={:key=>1}
=> {:key=>1}
irb(main):002:0> hash.merge( :key => "new value" )
=> {:key=>"new value"}
irb(main):003:0> hash
=> {:key=>1}

The hash is merged properly.

	robert