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
···
--
Posted via http://www.ruby-forum.com/.
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
--
Posted via http://www.ruby-forum.com/.
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.
--
Paul Lutus
http://www.arachnoid.com
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 ?
Thanksitems.delete_at(3)
Just like in the documentation.
Did he want to remove the element at index 3,
or remove instances of 3?
Hal
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 ?
Thanksitems.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 == 3 }
Removes all items matching "3".
--
Paul Lutus
http://www.arachnoid.com
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 == 3 }
items.delete 3
Removes all items matching "3".
as you said
Cheers
Robert
On 8/20/06, Paul Lutus <nospam@nosite.zzz> wrote:
--
Paul Lutus
http://www.arachnoid.com
--
Deux choses sont infinies : l'univers et la bêtise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.
- Albert Einstein
Jeffrey Schwab wrote:
/ ...
If your theory is correct, then:
items.delete_if { |x| x == 3 }
Removes all items matching "3".
items.delete(3)
Yes, better. I overlooked this approach.
--
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
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: inlineOn 8/20/06, Paul Lutus <nospam@nosite.zzz> 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
--
Posted with http://DevLists.com. Sign up and save your mailbox.