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
Paul L. wrote:
items.delete_at(3)
Just like in the documentation.
Did he want to remove the element at index 3,
or remove instances of 3?
Hal
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.
Hal F. wrote:
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 }
Removes all items matching “3”.
On 8/20/06, Paul L. [email protected] wrote:
items.remove(3) does not work
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
–
Paul L.
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
On Sunday, August 20, 2006, at 7:33 PM, Robert D. wrote:
Nicolas Benady wrote:
If your theory is correct, then:
Cheers
Robert–
Paul L.
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