From: Daniel Baird Date: 2006-03-15T13:14:41+09:00 Subject: Re: Enumerable#find return index ------=_Part_4982_22864780.1142396065777 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline try arr.index(3) ;Daniel On 15/03/06, Tod McIntyre wrote: > > This is quite embarassing because I Don't consider myself a poor > programmer, but I just started looking at ruby the other day. > > Blocks seem to be a good way to iterate through something to search for > an entry for instance. It's easy to return the object that meets > certain criteria using blocks but I'm finding it hard to return the > index of that particular object in, say, an array. > > as an example > > arr=3D[4,1,3,7] > arr.find { |f| f=3D=3Dsomeval } > will return the val within arr that matches someval, which doesn't > really help me because I already have someval > > How do I actually return the index in arr to the first match of someval. > > so if someval =3D=3D 3, my block would return 2, for the above example > > > -- > Posted via http://www.ruby-forum.com/. > > -- Daniel Baird http://danielbaird.com (TiddlyW;nks! :: Whiteboard Koala :: Blog :: Things That Suck) [[My webhost uptime is ~ 92%.. if no answer pls call again later!]] ------=_Part_4982_22864780.1142396065777--