From: "Simon Kröger" Date: 2006-01-30T05:33:59+09:00 Subject: Re: Loop weirdness Jonathan Leighton wrote: > Hi, > > I'm going ever so slightly crazy over some looping behaviour. Here's a > simplified test case I made: Is this what you are trying to do? def categorise(items) items.inject(Hash.new([])) do |h, item| h[item[:num]] += [item[:foo]]; h end.map{|k, v| {:num => k, :items => v}} end (sorry, i know this wasn't your question - i love refactoring and hope there is a trick or two in it you didn't came across yet) cheers Simon