From: Robert Klemme Date: 2006-02-06T01:13:20+09:00 Subject: Re: Ruby feature request - enum.detect_index James Edward Gray II wrote: > On Feb 5, 2006, at 9:48 AM, Robert Klemme wrote: > >> Yukihiro Matsumoto wrote: >>> Hi, >>> In message "Re: Ruby feature request - enum.detect_index" >>> on Sun, 5 Feb 2006 23:43:19 +0900, "jonT" writes: >>>> detect works great but doesn't supply the index of the match. It >>>> would be nice to have a method detect_index that returned the index >>>> rather than the object. >>> Nice idea. I'd rather name it 'find_index' though. >> >> Don't we have that already? >> >>>> %w{foo bar baz}.index "baz" >> => 2 >> >> Or am I missing something? > > You can not use a block of Ruby code to select the item you would > like an index for, in this example. Good point. In that case I'd just change the implementation of #index to either accept an argument or a block. This cannot break old code because at the moment blocks are not permitted / ignored. Kind regards robert