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=-2.6 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no 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 CD71A1F55B for ; Sat, 23 May 2020 12:39:10 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 2CB491209C2; Sat, 23 May 2020 21:38:46 +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 349E21209A5 for ; Sat, 23 May 2020 21:38:44 +0900 (JST) Received: by filterdrecv-p3mdw1-6dbfd75bfd-7ktlc with SMTP id filterdrecv-p3mdw1-6dbfd75bfd-7ktlc-19-5EC91969-16 2020-05-23 12:39:05.435165765 +0000 UTC m=+1875088.306672695 Received: from herokuapp.com (unknown) by ismtpd0047p1mdw1.sendgrid.net (SG) with ESMTP id 5hPlBFtTQWyIPdp1m4LYxA for ; Sat, 23 May 2020 12:39:05.336 +0000 (UTC) Date: Sat, 23 May 2020 12:39:05 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 74284 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 16908 X-Redmine-Issue-Author: ioquatix X-Redmine-Sender: Eregon 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?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr2yzcU4BAC=2FQYKsa+mAgw?= =?us-ascii?Q?7N0iVVsOiAFUoOxfD40Y5cJ0kmTTJ9sbeHFGeo1?= =?us-ascii?Q?I1I7vK=2FEvO274WHB3yRpZChjpCcLCYcQ1ywyGZ3?= =?us-ascii?Q?hhZWhg9w1eIYrTLcrL0IlKp+RS1c0O+HZ8n236C?= =?us-ascii?Q?AvabqPjWbzsg7mXeGVtEfxPU7ji90EskUU+VEw6?= =?us-ascii?Q?8=2FpLp9rcSKC3hmQPw=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 98492 Subject: [ruby-core:98492] [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 Eregon (Benoit Daloze). In other words, the current semantics of `return hash.default(nil) if hash.empty?` feel hacky and actually harmful to me. The user probably never expects to have the default_proc called with a `nil` key in many cases. ---------------------------------------- Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`. https://bugs.ruby-lang.org/issues/16908#change-85768 * 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/