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=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 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 240BE1F461 for ; Thu, 22 Aug 2019 19:57:02 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 61BF81209B1; Fri, 23 Aug 2019 04:56:53 +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 7388B1209A0 for ; Fri, 23 Aug 2019 04:56:51 +0900 (JST) Received: by filter0049p3las1.sendgrid.net with SMTP id filter0049p3las1-23877-5D5EF386-11 2019-08-22 19:56:54.329850931 +0000 UTC m=+438914.369520978 Received: from herokuapp.com (unknown [34.224.37.22]) by ismtpd0036p1iad2.sendgrid.net (SG) with ESMTP id p5v8HcGdQLK3XpznwikC5w for ; Thu, 22 Aug 2019 19:56:54.295 +0000 (UTC) Date: Thu, 22 Aug 2019 19:56:54 +0000 (UTC) From: shevegen@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70034 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16115 X-Redmine-Issue-Author: kke X-Redmine-Sender: shevegen 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?6lbdtOg4RDRLuxD00eQtQKgoNAsge5d4xND7cbMQd0xDG8iYE7RcQzNTkEO0dE?= =?us-ascii?Q?s7jmyPGxeuNiICrmHCyuvEOmJ2u5Irf+fhmnqKv?= =?us-ascii?Q?pTWueyfZ8sXRLLFCYcKXdSVGsaZkXwNww2P+c6H?= =?us-ascii?Q?+oyd6SMzaeYD9cnzTsZoPCNzWmWvp30kP=2FGtYOg?= =?us-ascii?Q?n6MHpZ0weS8hLkHcai3yMaDJDLb4T2IYIDw=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 94485 Subject: [ruby-core:94485] [Ruby master Feature#16115] Keyword arguments from method calls or ignore extra hash keys in splat 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 #16115 has been updated by shevegen (Robert A. Heiler). > I think this could open up some possibilities (or a can of worms). Some can call it a feature, other may call it a bug. :-) In regards to keyword arguments, though, I would wait a bit and see how/if https://bugs.ruby-lang.org/issues/14183 is decided upon (or not) at the upcoming dev meeting (at https://bugs.ruby-lang.org/issues/14183). In my opinion it would be best to not put more and more complexity into keyword arguments and related activities, such as the proposal here by suddenly retrofitting it into calling methods: def hello(who:) puts "Hello, #{who}!" end The net benefit to me here appears to be only that you can save a few characters (since you don't have to be explicit about the method) but that seems to be at odds, or at the least strange, and mostly implied behaviour. You can ask matz about his opinion of course but I think this should be decided after the other issues have been decided; and my personal opinion is to rather not want to make this all more complex. The complexity associated with this was already a source of bugs and confusion; I think jeremy events pointed this out before. hello(***{ who: 'world', foo: 'bar' }) # would ignore any extra keys As for triple-splat, I am against this; it seems to add more complexity for no real gain. If we have triple splats, do we then want quad-splats, and quadriple splats, all with special meaning? ---------------------------------------- Feature #16115: Keyword arguments from method calls or ignore extra hash keys in splat https://bugs.ruby-lang.org/issues/16115#change-80920 * Author: kke (Kimmo Lehto) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Just a thought, feel free to insta-close as stupid. Currently you can do this: ``` def hello(who:) puts "Hello, #{who}" end opts = { who: 'world' } hello(who) ``` Or: ``` def hello(who:, **_extra_opts) # without eating extra args, you get ArgumentError (unknown keyword: foo) puts "Hello, #{who}!" end hello(**{ who: 'world', foo: 'bar' }) ``` Or even this: ``` def hello(_obj = nil, who: _obj&.who || raise(ArgumentError, "missing who:")) puts "Hello, #{who}!" end hello(OpenStruct.new(who: 'world')) ``` 1) What if when you passed an object as an argument to a method that only accepts keyword arguments, the methods listed would be called? Then you could do: ``` require 'ostruct' ostruct = OpenStruct.new(who: 'world, foo: 'bar') def hello(who:) puts "Hello, #{who}!" end hello(ostruct) ``` 2) Or perhaps add some sort of "triple splat" that would either a) do the method calling thing described above or b) do the regular hash splatting like `**` but ignore any keys present that are not listed as keyword arguments: ``` require 'ostruct' ostruct = OpenStruct.new(who: 'world', foo: 'bar') def hello(who:) puts "Hello, #{who}!" end # a: hello(***ostruct) # would call ostruct.who to figure out `who:` # or b: (currently with ** raises ArgumentError (unknown keyword: foo)) hello(***{ who: 'world', foo: 'bar' }) # would ignore any extra keys ``` I think this could open up some possibilities (or a can of worms). -- https://bugs.ruby-lang.org/