From: Kevin Olbrich Date: 2006-08-20T21:41:53+09:00 Subject: Re: Remove from an array On Sunday, August 20, 2006, at 7:33 PM, Robert Dober wrote: >------=_Part_25421_29258161.1156070000118 >Content-Type: text/plain; charset=ISO-8859-1; format=flowed >Content-Transfer-Encoding: quoted-printable >Content-Disposition: inline > >On 8/20/06, Paul Lutus wrote: >> >> Hal Fulton wrote: >> >> > Paul Lutus wrote: >> >> Nicolas Benady wrote: >> >> >> >> >> >>>Hello, >> >>>I have an array, let's name it items[] >> >>>I want to remove an object in a elegant way >> >>>items.remove(3) does not work >> >>>How should I do ? >> >>>Thanks >> >>> >> >> >> >> >> >> items.delete_at(3) >> >> >> >> Just like in the documentation. >> >> >> > >> > Did he want to remove the element at index 3, >> > or remove instances of 3? >> >> I suppose I should have asked that before replying. :) >> >> If your theory is correct, then: >> >> items.delete_if { |x| x =3D=3D 3 } > >items.delete 3 > >> Removes all items matching "3". > > >as you said > >Cheers >Robert > >-- >> Paul Lutus >> http://www.arachnoid.com >> >> > This is slightly off-topic, but... To remove only the first item matching a value of 3, do this.. items.delete_at(items.index(3)) _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.