Issue #22021 has been updated by chucke (Tiago Cardoso). I get the point of avoiding mutating while iterating, but the point of `delete_if` is to mutate the array. there's nothing in its name hinting at it being based on the index, that's what `#delete_at` is for, so that's an implementation detail. I didn't check the implementation yet, so I may be oversimplifying it, but I don't see why the element ref can't be kept for post-comparison (although, if based on the `#each` impl, which is known to skip elements on mutation, I can understand your judgement). ---------------------------------------- Bug #22021: Array#delete_if may delete wrong object if array has been altered already https://bugs.ruby-lang.org/issues/22021#change-117205 * Author: chucke (Tiago Cardoso) * Status: Rejected * ruby -v: 4.0.2 * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- The simplest example I can come up with: ```ruby $ar = ar = [1, 2, 3, 4, 5] def del(i) $ar.delete(i) end ar.delete_if { |e| e == 2 ? (del(e) && true) : false } p ar #=> [1, 4, 5], and it should be [1, 3, 4, 5] ``` -- https://bugs.ruby-lang.org/