From: Brian Candler Date: 2008-10-28T21:19:16+09:00 Subject: Re: Hash.merge_add! extension - how does this code look? > self[k] = Array[self[k]] + Array[v] Oops, I meant to write: self[k] = Array(self[k]) + Array(v) Otherwise, if the value is already an array, it will be wrapped in another one. This does highlight a limitation of this API thought. What if the values themselves are arrays? h = { "foo" => [1,2] } h.merge_add!({ "foo" => [3,4] }) # do you want h = { "foo" => [[1,2], [3,4]] } ? In that case, it would be better to insist that the hash values are arrays in the first place, as shown by Stefan Rusterholz's collector example earlier. Also, are you happy for duplicate values to be inserted? h = { "foo" => "bar" } h.merge_add!({ "foo" => "bar" }) # h = { "foo" => ["bar", "bar"] } ? -- Posted via http://www.ruby-forum.com/.