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 8EDDF1F5AE for ; Wed, 29 Jul 2020 15:33:37 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 6DBDB120AA5; Thu, 30 Jul 2020 00:33:07 +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 47C84120AA4 for ; Thu, 30 Jul 2020 00:33:05 +0900 (JST) Received: by filterdrecv-p3iad2-5b55dcd864-9xqm9 with SMTP id filterdrecv-p3iad2-5b55dcd864-9xqm9-19-5F2196CC-C1 2020-07-29 15:33:32.777240868 +0000 UTC m=+2845451.736326035 Received: from herokuapp.com (unknown) by ismtpd0012p1iad1.sendgrid.net (SG) with ESMTP id 9jHSH23ESbmEggLY_NZy9w for ; Wed, 29 Jul 2020 15:33:32.630 +0000 (UTC) Date: Wed, 29 Jul 2020 15:33:32 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75188 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?BIevpND4vSwo23xjBdiu2JiCFc9ulkQifmjih55?= =?us-ascii?Q?ko3Bob1u5l1vD59ApGLMcawByDkJbiVfevOcMmk?= =?us-ascii?Q?Vz1WiEGCNgb6T6qjfNZ65OFyyKLhAGX7gi4EKlp?= =?us-ascii?Q?GFqiBdOnQUPRQb4xcvo+4VJyV82RSNtWYkjNZ8N?= =?us-ascii?Q?mMqga+S8kIeJI0zko=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99392 Subject: [ruby-core:99392] [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). Looks like this changed between Ruby 2.2 and 2.3. I'll update the documentation to remove the line, as I think it's an implementation detail (that is now wrong). ---------------------------------------- Bug #17058: Array#delete_if doesn't change array instantly https://bugs.ruby-lang.org/issues/17058#change-86796 * Author: erik_schlyter (Erik Schlyter) * Status: Open * 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/