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 BD2F61F4B4 for ; Fri, 9 Apr 2021 13:04:18 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 47A271212CD; Fri, 9 Apr 2021 22:03:13 +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 74A42120C05 for ; Fri, 9 Apr 2021 22:03:10 +0900 (JST) Received: by filterdrecv-c5749c756-727c5 with SMTP id filterdrecv-c5749c756-727c5-15-607050C3-D7 2021-04-09 13:04:03.956301237 +0000 UTC m=+1281616.644657672 Received: from herokuapp.com (unknown) by geopod-ismtpd-5-2 (SG) with ESMTP id C5qEPpYAQzWWEoCgYrc3xQ for ; Fri, 09 Apr 2021 13:04:03.857 +0000 (UTC) Date: Fri, 09 Apr 2021 13:04:03 +0000 (UTC) From: jean.boussier@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 79392 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: byroot 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?AchqQMoUBMcQgz7gop0XiYUiatGIY7E61JGsTL4FvjeXYp5HdbPGI4UsdkBYuu?= =?us-ascii?Q?KmrlOg9ZrPeM4j2wKxAYTPkSfuZO3Q1VEWZ=2FmyZ?= =?us-ascii?Q?2VN14lsMNyAzUcYYAKxOmXL1gUQyj0e0991F=2F7a?= =?us-ascii?Q?=2FvLwly83g=2FV0+onsK1E3j0eHvvmRh5x8qJzX0vU?= =?us-ascii?Q?WeeokSPB+Bs4YfOOnucuB2eaZtWOyKho82SC54P?= =?us-ascii?Q?iRSqmqYm=2FX5Onlcmc=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103346 Subject: [ruby-core:103346] [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 byroot (Jean Boussier). Arguably it's a bit of a stretch, but how would you handle: `foo(class_, class:)`? What if instead of mangling the variable name, there would be a way to tell the parser to interpret the next word as a regular name rather than a keyword? e.g.: ```ruby def check(arg, class:) arg.is_a?(\class) end ``` `\` being a common escaping character I think it the one that would make the most sense. And that would allow to make it work with regular parameters as well: ```ruby def diff(start, \end) \end - start end ``` Even though this use case is much less important, except for documentation purposes. ---------------------------------------- Feature #17785: Allow named parameters to be keywords https://bugs.ruby-lang.org/issues/17785#change-91436 * 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/