From: Bill Atkins Date: 2005-04-10T01:29:11+09:00 Subject: Re: Array#last_index ------=_Part_1362_18299710.1113064130243 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I don't think this should be all that slow. Ruby tracks the array's length= =20 as it grows, so all you're doing here is reading a variable from memory and= =20 subtracting one. Still, it would probably be a good idea to add this to=20 Array. On Apr 9, 2005 12:49 AM, jzakiya@mail.com wrote: >=20 > array.last returns the value of the last array element. >=20 > In many instances it is necessary to get the index value > of the last array element. This is necessary in many > sorting and searching algorithms, especially where the > arrays are dynamically changing in size. You can do it like: >=20 > class Array > def last_index; self.length - 1 end > end >=20 > But this is slower than necessary, because array.last > already computes/knows what the last index value is, > and thus the mechanism already exists to get this info. >=20 > I would really like to see this method added to class Array. > It is a nice complement to Array#last, and aides performance. >=20 > Jabari Zakiya >=20 >=20 --=20 $stdout.sync =3D true "Just another Ruby hacker.".each_byte do |b| ('a'..'z').step do|c|print c+"\b";sleep 0.007 end;print b.chr end; print "\n" ------=_Part_1362_18299710.1113064130243--