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=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 F22C51F9FD for ; Wed, 17 Mar 2021 05:31:43 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 8652A120AAD; Wed, 17 Mar 2021 14:30:42 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 50CD9120977 for ; Wed, 17 Mar 2021 14:30:41 +0900 (JST) Received: by filterdrecv-p3las1-c477c4585-7p8x7 with SMTP id filterdrecv-p3las1-c477c4585-7p8x7-20-60519438-16 2021-03-17 05:31:36.406659078 +0000 UTC m=+3048220.402506809 Received: from herokuapp.com (unknown) by geopod-ismtpd-4-2 (SG) with ESMTP id I-THUD-oTumVfH2_UIp9YQ for ; Wed, 17 Mar 2021 05:31:36.137 +0000 (UTC) Date: Wed, 17 Mar 2021 05:31:36 +0000 (UTC) From: matz@ruby.or.jp Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 78935 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 16908 X-Redmine-Issue-Author: ioquatix X-Redmine-Sender: matz 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?bXEIHGfdFwsIlBTndiToCp=2Fmc2rfxRD2sZAksRKJIHUNngfB3NRfdpioI+mNop?= =?us-ascii?Q?ekZed7E=2FiPF0PR609HHxniU6lKPx4nVDZR1XFqq?= =?us-ascii?Q?6MboWDKJoOwGT+K8uXrIU4Hri00P8rGleLQoqu7?= =?us-ascii?Q?kf1NoWBigZduf+0+=2FyR2x3nFHukX7HRiZChbOMG?= =?us-ascii?Q?b=2FzOpq0sH2Swk7wldznEtTzPZeBYGVLiDRA=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 102900 Subject: [ruby-core:102900] [Ruby master Bug#16908] Strange behaviour of Hash#shift when used with `default_proc`. 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 #16908 has been updated by matz (Yukihiro Matsumoto). I don't remember why I made this behavior. Now I think `#shift` should return `nil` for an empty hash, without calling its default value, in the long run. @naruse claims the change should be postponed to `3.2` or later if we make the change. Matz. ---------------------------------------- Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`. https://bugs.ruby-lang.org/issues/16908#change-90961 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal * ruby -v: 2.7.0 * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- I don't have any strong opinion about this, but I observed the following behaviour which I thought was confusing. Maybe it's okay, or maybe we should change it to be more consistent. ``` hash = Hash.new{|k,v| k[v] = 0} hash.shift # => 0 hash.shift # => [nil, 0] ``` My feeling was, both cases should return `[nil, 0]`. -- https://bugs.ruby-lang.org/