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.4 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 0951E1F463 for ; Fri, 13 Sep 2019 17:00:43 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 758EA120935; Sat, 14 Sep 2019 02:00:28 +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 1D4AA120925 for ; Sat, 14 Sep 2019 02:00:25 +0900 (JST) Received: by filter0071p3iad2.sendgrid.net with SMTP id filter0071p3iad2-18732-5D7BCB28-6B 2019-09-13 17:00:24.522557637 +0000 UTC m=+81042.165094259 Received: from herokuapp.com (unknown [54.242.69.183]) by ismtpd0012p1iad1.sendgrid.net (SG) with ESMTP id iHvhUZIWSP-OJh2Sy-Qcfw for ; Fri, 13 Sep 2019 17:00:24.401 +0000 (UTC) Date: Fri, 13 Sep 2019 17:00:24 +0000 (UTC) From: daniel@dan42.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70485 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16157 X-Redmine-Issue-Author: Dan0042 X-Redmine-Sender: Dan0042 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?8sy4RigFvRTdBfCVJrT9zb2J88PC92TMQwdNgaWYaq4LEAr3kRdF=2Fzs3q4gJ=2FU?= =?us-ascii?Q?Sp77YYH0xl3jqQ97buvD=2FhDsmorLf721Cbe=2F=2FXL?= =?us-ascii?Q?cUy0=2F8hQRTHvwKTn2izzokm6=2F=2FMjjWc0QnBxWed?= =?us-ascii?Q?edyunnnuuzSmIRtEQa=2FipevgGAoDSNVi2BMy8Ir?= =?us-ascii?Q?Vh8FtVsJtdZzu9Kd6mrVs1waXm2YkTvy8VQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 94931 Subject: [ruby-core:94931] [Ruby master Misc#16157] What is the correct and *portable* way to do generic delegation? 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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16157 has been updated by Dan0042 (Daniel DeLorme). In that case I'd like to make one last suggestion. For a method with `*args`, if the method is called with keyword arguments, = flag `args` in some way (instance variable?) so that, in that method only, = a call with `*args` would result in the last argument being passed as a key= word argument. Yes, it's a hack, but it's a better hack than `pass_keywords= ` imho. This would make the migration less tedious, less confusing, less error-pron= e, and postpone this whole delegation mess to a date when it's easier to de= al with. I really think this migration should be split into "should be done= now" and "easier to do once 2.6 is no longer supported". My 2=A2 ---------------------------------------- Misc #16157: What is the correct and *portable* way to do generic delegatio= n? https://bugs.ruby-lang.org/issues/16157#change-81547 * Author: Dan0042 (Daniel DeLorme) * Status: Open * Priority: Normal * Assignee: = ---------------------------------------- With the keyword argument changes in 2.7 we must now specify keyword argume= nts explicitly when doing generic delegation. But this change is not compat= ible with 2.6, where it adds an empty hash to the argument list of methods = that do not need/accept keyword arguments. To illustrate the problem: ```ruby class ProxyWithoutKW < BasicObject def initialize(target) @target =3D target end def method_missing(*a, &b) @target.send(*a, &b) end end class ProxyWithKW < BasicObject def initialize(target) @target =3D target end def method_missing(*a, **o, &b) @target.send(*a, **o, &b) end end class Test def args(*a) a end def arg(a) a end def opts(**o) o end end # 2.6 2.7 3.0 ProxyWithoutKW.new(Test.new).args(42) # [42] [42] [42= ] ok ProxyWithoutKW.new(Test.new).arg(42) # 42 42 42 = ok ProxyWithoutKW.new(Test.new).opts(k: 42) # {:k=3D>42} {:k=3D>42} +warn = [{:k=3D>42}] incompatible with >=3D 2.7 ProxyWithKW.new(Test.new).args(42) # [42, {}] [42] [42= ] incompatible with <=3D 2.6 ProxyWithKW.new(Test.new).arg(42) # error 42 42 = incompatible with <=3D 2.6 ProxyWithKW.new(Test.new).opts(k: 42) # {:k=3D>42} {:k=3D>42} +warn = {:k=3D>42} must ignore warning? cannot use pass_positional_hash in 2.6 ``` I don't know how to solve this, so I'm asking for the **official** correct = way to write portable delegation code. And by **portable** I mean code that= can be used in gems that target ruby 2.6 and above. -- = https://bugs.ruby-lang.org/ Unsubscribe: