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.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 4AE9D1F4B4 for ; Sat, 10 Apr 2021 17:04:27 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 3F613120D8D; Sun, 11 Apr 2021 02:03:24 +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 3EDF9120D84 for ; Sun, 11 Apr 2021 02:03:22 +0900 (JST) Received: by filterdrecv-59db977c98-mlp7z with SMTP id filterdrecv-59db977c98-mlp7z-14-6071DA8F-AA 2021-04-10 17:04:15.872900721 +0000 UTC m=+1382415.071559561 Received: from herokuapp.com (unknown) by geopod-ismtpd-3-1 (SG) with ESMTP id Z4h3Z3JaTeetGnVERkOKuQ for ; Sat, 10 Apr 2021 17:04:15.715 +0000 (UTC) Date: Sat, 10 Apr 2021 17:04:15 +0000 (UTC) From: marcandre-ruby-core@marc-andre.ca Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 79424 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?aOswrbB0IQq2dEAkIvUO0LY1GrvQEfOStY4t7H4?= =?us-ascii?Q?40qsuH96uGnn0PaAiVYJ4EHLpTT2rhhW6JfU=2Fv8?= =?us-ascii?Q?kdD0TH5MrPssr3abGSbs4AW=2FzjWKNJv183Y0Ord?= =?us-ascii?Q?jjNC5K4D0Zb7VYJxzqfD7yT5WKkkkdCvqH05N6N?= =?us-ascii?Q?MAMcFhfA75WKXA2ak=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103377 Subject: [ruby-core:103377] [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). My main objection to `local_variable_get` is that it's super verbose / ugly. > How would you handle `foo(class_, class:)?` Setting local `class_` would not happen here. It would only happen if not shadowing an existing variable (except maybe if that other variable was also created the same way) I like `\class` too. ---------------------------------------- Feature #17785: Allow named parameters to be keywords https://bugs.ruby-lang.org/issues/17785#change-91470 * 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/