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=-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 6B1A91F4B4 for ; Fri, 9 Apr 2021 17:59:43 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 72C33120C46; Sat, 10 Apr 2021 02:58:41 +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 E4359120C41 for ; Sat, 10 Apr 2021 02:58:39 +0900 (JST) Received: by filterdrecv-59db977c98-mlp7z with SMTP id filterdrecv-59db977c98-mlp7z-14-60709607-12 2021-04-09 17:59:35.216835662 +0000 UTC m=+1299334.415494528 Received: from herokuapp.com (unknown) by ismtpd0166p1iad2.sendgrid.net (SG) with ESMTP id nGvYTiveRdCnyw-wg9XegQ for ; Fri, 09 Apr 2021 17:59:35.103 +0000 (UTC) Date: Fri, 09 Apr 2021 17:59:35 +0000 (UTC) From: eregontp@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 79397 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17785 X-Redmine-Issue-Author: marcandre X-Redmine-Issue-Assignee: matz 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?KippOI8ZHtTweq7XfQzW93937kJ4QNWwSBuHnaMEcr2nyPkkFFmIjCmf3NGk=2FD?= =?us-ascii?Q?yiCyJ7uv=2F4k7hKMepNE0drReP4EEQyoHCLornzT?= =?us-ascii?Q?+yb+y9G4iVmRIfeT8gnHRrms8aYOgnSwJtNve8Z?= =?us-ascii?Q?B10TfWwxAnRXg1anASK35lNTBMTxK=2F8GbqTJYWi?= =?us-ascii?Q?AlndlHQiBgkx001Ih=2FdmgB1JjPe1XJUkKHQ=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103350 Subject: [ruby-core:103350] [Ruby master Feature#17785] Allow named parameters to be keywords 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 #17785 has been updated by Eregon (Benoit Daloze). I like @byroot's idea to solve the more general issue and not just this specific instance. marcandre (Marc-Andre Lafortune) wrote in #note-3: > Clearly, `class_` is much simpler and much faster than `binding.local_variable_get(:class)`... It can be the same performance with a JIT and escape analysis (i.e., it's the same on TruffleRuby). ---------------------------------------- Feature #17785: Allow named parameters to be keywords https://bugs.ruby-lang.org/issues/17785#change-91441 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- We should allow named parameters to be keywords and use add a trailing `_` to the corresponding variable: ```ruby def check(arg, class:) arg.is_a?(class_) end check(42, class: Integer) # => true ``` Currently, if we want such an API we have to use `**rest`: ```ruby def check(arg, **rest) class_ = rest.fetch(:class) { raise ArgumentError('missing keyword: :class')} if rest.size > 1 unknown = rest.keys - [:class] raise ArgumentError("unknown keyword(s): :#{unknown.join(', :')}) end arg.is_a?(class_) end ``` This is very verbose, much less convenient, much less readable, prevents `steep` from generating the proper signature, etc. We should do the same for pattern match. -- https://bugs.ruby-lang.org/