From: "David A. Black" Date: 2008-08-25T20:54:56+09:00 Subject: Re: indices of non nil elements in an array Hi -- On Mon, 25 Aug 2008, Patrick Doyle wrote: > a = [] > a[10] = "foo" > > a.nitems returns a count of the non-nil, items. What is the simplest > way to return the indices of "a" that are not nil? > > I'm sure there is some simple elegant way to do this, but I can't figure it out. Try this: (0...a.size).reject {|i| a[i].nil? } or select for a[i] if you don't mind losing false as well as nil. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL See http://www.rubypal.com for details and updates!