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.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 D1B861F4B4 for ; Thu, 8 Apr 2021 16:55:54 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B10241211BF; Fri, 9 Apr 2021 01:54:53 +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 8ECFB1211BF for ; Fri, 9 Apr 2021 01:54:51 +0900 (JST) Received: by filterdrecv-p3iad2-7d7c446bd4-bjl68 with SMTP id filterdrecv-p3iad2-7d7c446bd4-bjl68-20-606F3595-52 2021-04-08 16:55:49.647457923 +0000 UTC m=+1376563.970080208 Received: from herokuapp.com (unknown) by ismtpd0169p1iad2.sendgrid.net (SG) with ESMTP id sDeBEdPISl2dXTCDI9gRng for ; Thu, 08 Apr 2021 16:55:49.634 +0000 (UTC) Date: Thu, 08 Apr 2021 16:55:49 +0000 (UTC) From: marcandre-ruby-core@marc-andre.ca Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 79358 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: marcandre 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?6=2FIMxCQLDposcQf5wmbDAtfaKduBAO0bKyhL3BGZtMQ5q7K2TvpbN6A7JIyt9E?= =?us-ascii?Q?aOU+Ix9uy2xYf9F+5hP9u2W2+EuYsiEG6BgqLff?= =?us-ascii?Q?HoisrYJYTCFXZNfLppnkxqUvHj+P7VrquFTbvV2?= =?us-ascii?Q?wCxzGqds69j7LKqlacUxMa17eve4XyD+50L+HlY?= =?us-ascii?Q?X7LS3CHMa9KE0moq9f4le1au7lodC6TJCSV9JW8?= =?us-ascii?Q?Ji1WTcsVgMLepbPFAnu2L+=2FQ+Qpl5L0w8era=2Ff?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103312 Subject: [ruby-core:103312] [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 marcandre (Marc-Andre Lafortune). Clearly, `class_` is much simpler and much faster than `binding.local_variable_get(:class)`... ---------------------------------------- Feature #17785: Allow named parameters to be keywords https://bugs.ruby-lang.org/issues/17785#change-91396 * 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/