From: dblack@... Date: 2005-12-14T00:43:31+09:00 Subject: Re: Array.invert Hi -- On Tue, 13 Dec 2005, Christer Nilsson wrote: > I would like to see invert "rubyfied". > (Yes, I'm trying to get a grip of what this word means :-) Aren't we all? But the trying is so much fun :-) Here's a version that might be more idiomatic, and that passes all your tests: class Array def invert res=[] each_with_index do |e,i| if e e.each do |f| (res[f] ||= []) << i end end end res end end David -- David A. Black dblack@wobblini.net "Ruby for Rails", forthcoming from Manning Publications, April 2006!