From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 139AF1F5AE for ; Wed, 29 Jul 2020 15:37:37 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 2EFD6120AAC; Thu, 30 Jul 2020 00:37:06 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 64C12120AAB for ; Thu, 30 Jul 2020 00:37:04 +0900 (JST) Received: by filterdrecv-p3mdw1-75c584b9c6-xpzlh with SMTP id filterdrecv-p3mdw1-75c584b9c6-xpzlh-18-5F2197BC-9 2020-07-29 15:37:32.131146164 +0000 UTC m=+2845675.484338868 Received: from herokuapp.com (unknown) by geopod-ismtpd-4-2 (SG) with ESMTP id JUPYCHNwR0uaXoPn4PO1_A for ; Wed, 29 Jul 2020 15:37:32.039 +0000 (UTC) Date: Wed, 29 Jul 2020 15:37:32 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75190 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17058 X-Redmine-Issue-Author: erik_schlyter X-Redmine-Sender: jeremyevans0 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?RVE3t853K5scBhbmJHUzZTFFeVC=2FZSUmHZ0Dc+26wcEi2CTgsF1oz0wTSSxGGN?= =?us-ascii?Q?BIpxrENXgtN3dGLD50+8srEMyyiwwhxL9RIrjAB?= =?us-ascii?Q?sQgQEDwrJTUbN0PAKvqCWsyZ3NiabZgjT9gvXx0?= =?us-ascii?Q?MUeqtmN6=2FS62zDWsgigF5KamecGSv5sTsTQlF=2Fz?= =?us-ascii?Q?NJQ6XxdJXfmpC2sXqAEk5YgVCxlm9xs8bSo5fTa?= =?us-ascii?Q?bUc+W8MWKgk1f7E3c=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99394 Subject: [ruby-core:99394] [Ruby master Bug#17058] Array#delete_if doesn't change array instantly X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17058 has been updated by jeremyevans0 (Jeremy Evans). Status changed from Open to Closed Actually, this was already fixed in commit:9fc25811d59422355fc3a0ed0f28155e4e47267f. ---------------------------------------- Bug #17058: Array#delete_if doesn't change array instantly https://bugs.ruby-lang.org/issues/17058#change-86798 * Author: erik_schlyter (Erik Schlyter) * Status: Closed * Priority: Normal * ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- According to the documentation: https://ruby-doc.org/core-2.7.1/Array.html#method-i-delete_if "The array is changed instantly every time the block is called, not after the iteration is over." I've tried printing the array while iterating it: ``` a = [1,2,3,4,5,6,7] a.delete_if{|x| puts "During iteration: #{a}" x % 2 == 0 } puts "After iteration: #{a}" ``` The output is as follows: ``` During iteration: [1, 2, 3, 4, 5, 6, 7] During iteration: [1, 2, 3, 4, 5, 6, 7] During iteration: [1, 2, 3, 4, 5, 6, 7] During iteration: [1, 3, 3, 4, 5, 6, 7] During iteration: [1, 3, 3, 4, 5, 6, 7] During iteration: [1, 3, 5, 4, 5, 6, 7] During iteration: [1, 3, 5, 4, 5, 6, 7] After iteration: [1, 3, 5, 7] ``` This functionality has changed somewhere between 2.2.2 and 2.4.0. When I use "ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]", I get the following (correct) output: ``` During iteration: [1, 2, 3, 4, 5, 6, 7] During iteration: [1, 2, 3, 4, 5, 6, 7] During iteration: [1, 3, 4, 5, 6, 7] During iteration: [1, 3, 4, 5, 6, 7] During iteration: [1, 3, 5, 6, 7] During iteration: [1, 3, 5, 6, 7] During iteration: [1, 3, 5, 7] After iteration: [1, 3, 5, 7] ``` When I use "ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]" or the latest (2.7.1), I get the wrong output. The functionality doesn't seem crucial, but the documentation should be correct. -- https://bugs.ruby-lang.org/