From: Stefan Rusterholz Date: 2008-10-27T16:21:09+09:00 Subject: Re: Hash.merge_add! extension - how does this code look? Greg Hauptmann wrote: > thanks for highlighting this! Is the quickest way to normalise to Array > via > the following? > hashitem.instance_of?(Array) ? hashitem : [hashitem] If you're building up the hash yourself then I'd use the following idiom: collector = Hash.new { |h,k| h[k] = [] } collector['key1'] << 'value1' collector['key2'] << 'value1' collector['key1'] << 'value2' p collector Simplifies adding to and reading from the hash. But be aware that with the hash having a different default value than nil, you can't use 'if collector[key] then' to test for existence of a key anymore, you have to use has_key?. If you're not building the hash up yourself, then yes, I'd use what you wroten in an each loop and override the existing value. Regards Stefan -- Posted via http://www.ruby-forum.com/.