From: Yukihiro Matsumoto Date: 2006-10-11T08:20:00+09:00 Subject: Re: [ ruby-Bugs-6090 ] Loop over array.delete breaks at first hit Hi, In message "Re: [ ruby-Bugs-6090 ] Loop over array.delete breaks at first hit" on Wed, 11 Oct 2006 07:33:58 +0900, writes: | for user in @users | if not Foo.is_foo(user.id) | @users.delete(user) | end | end | |first i thought i'd have a bug in my select statements because not all users were filtert. the effect was that the looped breaked at first hit. |then i tried | | @users.delete_if {|user| not Foo.is_foo(user.id) } | |which worked fine. i think both versions should do the same. Modifying iterating array inside the loop may fail. Do it with your own risk. Checking it may hinder the performance. As you've found out by yourself, delete_if is your friend for the purpose. It's shorter, faster, and more convenient. matz.