From: Robert Klemme Date: 2006-03-16T00:53:49+09:00 Subject: Re: Enumerable#find return index "Tod McIntyre" wrote in message news:859233703646963b97fe343fb84b6e0f@ruby-forum.com... > Robert Klemme wrote: >> "Tod McIntyre" wrote in message >> news:da9c35364b80a5c4e9e603e0db41190a@ruby-forum.com... >>> arr=[4,1,3,7] >>> arr.find { |f| f==someval } >>> will return the val within arr that matches someval, which doesn't >>> really help me because I already have someval >> >> Yeah, but this is just a special case. With a block you can employ >> arbitrary selection criteria - not just ==. >> >>> How do I actually return the index in arr to the first match of >>> someval. >>> >>> so if someval == 3, my block would return 2, for the above example >> >> As Ross and Daniel have pointed out already, use #index. >> >> Kind regards >> >> robert > > Once again I knew this would be a simple answer!! I thank you for your > quick responses. Obviously I should be reading the api more thoroughly > before posting. Ah, don't bother. The API of the standard lib has it's humps and bumps (for example not fully consistent usage of ! for destructive methods etc.) so it's normal to fall into one or the other pit initially. Kind regards robert