Re: Iterate through array and delete if match



Tim Hunter wrote:
jackster the jackle wrote:
puts range
end
end

Is this the correct way to delete matched entries from an array?

Thanks

John

Use delete_if instead.

Or Array#reject!

deleting while iterating with each is undefined behavior. It's like
sawing off the tree branch you are sitting on.
--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Dumb question on Iterating over Collections
    ... I know you can't modify the objects of a collection when iterating ... So what's the standard practice for deleting all the items ... bunch of stuff. ... Should I create and array, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Dumb question on Iterating over Collections
    ... Does deleting the object remove it from the collection as well? ... > I know you can't modify the objects of a collection when iterating ... > bunch of stuff. ... Should I create and array, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: malloc() / calloc() weirdness
    ... > often undefined behavior then happens because the following code is usually ... As long as all other uses of the array ... are similar (iterating n times through the array), ... caller doesn't have to special-case this situation, ...
    (comp.unix.programmer)
  • Re: Adjacent arrays in C99
    ... Same result as the first example -- undefined behavior. ... terms of a pointer pointing into, or one past, 'an array object'. ... Standard says that no restrictions apply on what implementations ...
    (comp.std.c)
  • Re: SSCANF
    ... This gives undefined behavior. ... You're trying to modify ... in this context will evalutate to pointers to their ... array of three char). ...
    (comp.lang.c)