From: badboy Date: 2009-04-28T21:56:47+09:00 Subject: Re: Is there anything like Array#Index that takes a block? Lee Griffiths schrieb: > 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. hm...oh =/ ruby 1.8.7 (and 1.9.1, too)