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.8 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 764581F55B for ; Sat, 23 May 2020 02:38:40 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 0F5BF120999; Sat, 23 May 2020 11:38:12 +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 0C5B6120994 for ; Sat, 23 May 2020 11:38:09 +0900 (JST) Received: by filterdrecv-p3iad2-8ddf98858-xxtk7 with SMTP id filterdrecv-p3iad2-8ddf98858-xxtk7-19-5EC88CA8-2 2020-05-23 02:38:32.034868584 +0000 UTC m=+5016661.906970747 Received: from herokuapp.com (unknown) by ismtpd0087p1mdw1.sendgrid.net (SG) with ESMTP id _yePHc58RJmq1pdWQiVikQ for ; Sat, 23 May 2020 02:38:31.678 +0000 (UTC) Date: Sat, 23 May 2020 02:38:32 +0000 (UTC) From: samuel@oriontransfer.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 74280 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 16908 X-Redmine-Issue-Author: ioquatix X-Redmine-Sender: ioquatix 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?cjxb6GWHefMLoR50bkJBcGo6DRiDl=2FNYcMZdY+Wj30S=2FN0Grvr17=2FGsSvoUbiM?= =?us-ascii?Q?YWFBhb=2FRmN63xc=2FwSzAycUkawmDJNh521x=2FVPGp?= =?us-ascii?Q?ct18WSpAn1gORLu3eEjuvegTmbda64UXbPLcwxc?= =?us-ascii?Q?xlD6FPz6DaDNcyuijUeiooKBcVpNLPzsiMu5Ku4?= =?us-ascii?Q?vv4VyZ3vXL70m+A=2F5LA7ikUtdJEqSH1lFIoBKuU?= =?us-ascii?Q?lfB41LVCR7jua0D5s=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 98488 Subject: [ruby-core:98488] [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 ioquatix (Samuel Williams). @jeremyevans0 I agree with your assessment, however that hash does not have default_proc so I assume that it would return `nil` after all key-value pairs are `shift`ed out. That's different from invoking `default_proc` and returning `[nil, 0]`. ---------------------------------------- Bug #16908: Strange behaviour of Hash#shift when used with `default_proc`. https://bugs.ruby-lang.org/issues/16908#change-85764 * 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/