From: Matthew Pounsett Date: 2010-02-02T03:11:08+09:00 Subject: Re: Adding keys to a hash in a loop On 2010/02/01, at 13:07, Jack Bauer wrote: > Marnen Laibow-Koser wrote: >> The same way you assign to a hash element outside a loop: >> output_hash[item.name] = value . << is only useful with arrays, not >> hashes. > > > Thanks, I know << is only for arrays. Using = will only end up with one > key and not all 10 that I'm trying to get. Hi Jack. The suggestion is not to just replace << with = like this: output.each do |item| output_hash = {item.name => []} end The suggestion is to use = in a normal hash assignment: output.each do |item| output_hash[item.name] = [] end HTH, Matt