From: Lee Griffiths Date: 2009-04-28T21:55:35+09:00 Subject: Re: Is there anything like Array#Index that takes a block? badboy wrote: > Lee Griffiths schrieb: >> I would like to avoid doing : >> Array.index(Enumerable.find { |blarg| blarg =~ /blah/ }) >> >> as that traverses the array twice. Is there any built in method that >> does this for me? That is, it's a method that takes a block and returns >> the index of the first element for which this block returns true? >> >> Thanks > yes... it's called Array#index *scnr* > ri says: > array.index(obj) -> int or nil > array.index {|item| block} -> int or nil > ... > If a block is given instead of an argument, returns first > object for which _block_ is true. > > so...just use #index with a blocck Which version of Ruby is that for? My ri, irb and ruby don't confirm this. I'm using Ruby 1.8.6. Additionally http://www.ruby-doc.org/core/ claims that Array#index only has a single implementation. -- Posted via http://www.ruby-forum.com/.