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-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.0 required=3.0 tests=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_PASS 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 A3019211B4 for ; Wed, 5 Dec 2018 08:28:59 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 3AFB91214D8; Wed, 5 Dec 2018 17:28:58 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id E058C120DE7 for ; Wed, 5 Dec 2018 17:28:55 +0900 (JST) Received: by filter0146p3las1.sendgrid.net with SMTP id filter0146p3las1-22408-5C078C45-25 2018-12-05 08:28:53.512450966 +0000 UTC m=+135073.857741690 Received: from herokuapp.com (ec2-50-17-41-137.compute-1.amazonaws.com [50.17.41.137]) by ismtpd0034p1iad2.sendgrid.net (SG) with ESMTP id 3bpyrYEZTKyu0_MdHy17bQ for ; Wed, 05 Dec 2018 08:28:53.210 +0000 (UTC) Date: Wed, 05 Dec 2018 08:28:54 +0000 (UTC) From: sawadatsuyoshi@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 65698 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15381 X-Redmine-Issue-Author: sawa X-Redmine-Sender: sawa 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: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4T0G3wOuN3hjlXeTcmnO4raPfEJvzel21Piv R4El/T8gu3viPFGLoOEUbzsmh6+whz83894OgHoRSY2RAElqofhtnBvrqVGNbP+JoGLhP2CdDhKvmh jqBoJwWjzEIEB07G3hzu8roI4ybwLDOhCU2ixfPwm+GfdYgFtQwwtrAPKQ== X-ML-Name: ruby-core X-Mail-Count: 90305 Subject: [ruby-core:90305] [Ruby trunk Feature#15381] Let double splat call `to_hash` implicitly 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 #15381 has been updated by sawa (Tsuyoshi Sawada). In case my intention was not clear, in the example I gave for the double splat, I expected `**nil` to be evaluated as `{}`. ---------------------------------------- Feature #15381: Let double splat call `to_hash` implicitly https://bugs.ruby-lang.org/issues/15381#change-75411 * Author: sawa (Tsuyoshi Sawada) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- The single splat calls `to_a` implicitly on the object (if it is not an array already) so that, for example, we have the convenience of writing conditions in an array literal: ```ruby a = [ *(:foo if some_condition), *(:bar if another_condition), ] ``` And the ampersand implicitly calls `to_proc` on the object (if it is not a proc already) so that we can substitute a block with an ampersand followed by a symbol: ```ruby some_method(&:some_method_name) ``` Unlike the single splat and ampersand, the double splat does not seem to implicitly call a corresponding method. I propose that the double splat should call `to_hash` implicitly on the object if it not already a hash so that we can, for example, write a condition in a hash literal as follows: ```ruby h = { **({a: 1} if some_condition), **({b: 2) if another_condition), } ``` There may be some other benefits of this feature that I have not noticed yet. -- https://bugs.ruby-lang.org/