2008/2/19, MenTaLguY <mental / rydia.net>:
> On Wed, 20 Feb 2008 07:15:52 +0900, Sebastian Hungerecker <sepp2k / googlemail.com> wrote:
> >> .. is there a better way?
> >
> > @categories = Hash.new {Array.new}
> > pagelist.each do |resource|
> >   @categories[resource.tag] << resource
> > end
>
> Although it is specific to hashes, when this is applicable I do
> think it can be a better approach than the more general approach
> I outlined in my other email.

But it needs the fix Joel pointed out:

@categories = Hash.new {|h,k| h[k] = []}

Theoretically this could even be more efficient than

(@categories[k] ||= []) << v

because the check is done only once per missing key.

Kind regards

robert

-- 
use.inject do |as, often| as.you_can - without end