Bug #5752

Array#delete_if side effects due to changeset r32360

Added by Thomas Leitner over 2 years ago. Updated over 2 years ago.

[ruby-core:41616]
Status:Closed
Priority:Normal
Assignee:-
Category:doc
Target version:1.9.3
ruby -v:ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux] Backport:

Description

It seems that the changeset r32360 introduced another side effect. Here are two IRB sessions, one in ruby-1.9.2-p136 and the other in ruby-1.9.3-p0:

ruby-1.9.2-p136 :001 > x = [1,2,3,4,5,6,7,8,9]
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
ruby-1.9.2-p136 :002 > x.delete_if {|i| i == x[i-1]}
=> []

ruby-1.9.3-p0 :001 > x = [1,2,3,4,5,6,7,8,9]
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
ruby-1.9.3-p0 :002 > x.delete_if {|i| i == x[i-1]}
=> [2, 3, 4, 5, 6, 7, 8, 9]

If this is indeed the intended behaviour, it should probably be documented clearly that the array is changed instantly every time the block is called and not after the iteration is over.

array.c.patch Magnifier - fix delete_if (719 Bytes) Yura Sokolov, 12/14/2011 07:03 PM

Associated revisions

Revision 34048
Added by Nobuyoshi Nakada over 2 years ago

  • array.c (rbaryrejectbang, rbarydeleteif): update rdoc. documentation from Thomas Leitner in . [Bug #5752]

History

#1 Updated by Yura Sokolov over 2 years ago

Actually, it were next changeset r32373

#2 Updated by Yura Sokolov over 2 years ago

#3 Updated by Nobuyoshi Nakada over 2 years ago

  • Category changed from core to doc
  • Status changed from Open to Closed

Also available in: Atom PDF