From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-07-31T08:14:59+09:00 Subject: Re: collect_by On Thu, 31 Jul 2003 08:17:44 +0900, dblac wrote: > On Thu, 31 Jul 2003, Simon Strandgaard wrote: >> Please enligthen me :-) [snip] > (Another issue is that the way you've written it, h[...] will always > return the *same* array. But that's another matter :-) You can > circumvent that, in 1.8, with: h = Hash.new { [] } ) Oh.. I luckily forgot about this. Still it won't work.. What am I doing wrong ? module Enumerable def collect_by h = Hash.new { Array.new } # braces :-) each{|i| h[yield(i)].push i} h end end a = (1..10).to_a p a.collect_by {|i| i % 2} #=> {} -- Simon Strandgaard