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 C17191F4C0 for ; Wed, 23 Oct 2019 00:47:43 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C4EFA12099A; Wed, 23 Oct 2019 09:47:33 +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 CC983120969 for ; Wed, 23 Oct 2019 09:47:31 +0900 (JST) Received: by filter0150p3mdw1.sendgrid.net with SMTP id filter0150p3mdw1-14835-5DAFA329-14 2019-10-23 00:47:37.065849793 +0000 UTC m=+94308.374823531 Received: from herokuapp.com (unknown [52.91.158.104]) by ismtpd0054p1mdw1.sendgrid.net (SG) with ESMTP id QfA4ZgSPTtaHYE2apZUTsA for ; Wed, 23 Oct 2019 00:47:36.968 +0000 (UTC) Date: Wed, 23 Oct 2019 00:47:37 +0000 (UTC) From: manga.osyo@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 71078 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16273 X-Redmine-Issue-Author: osyo X-Redmine-Sender: osyo 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?EoIqruA4Er0CjiyK1+U6TJuuQMCAZ3OX2ybarlx6ke4jN7xfDx959+6QYy=2FbuX?= =?us-ascii?Q?3G7uNPfe7ydWXYqD7UwlotV6o84EH1eXJv1PFl1?= =?us-ascii?Q?yAombfy+tJGipZHKQYU077zbQt7nhIlUntYNDlp?= =?us-ascii?Q?R3QMT7WIYsCDuScX9J=2F55SEIA9F7Bqp7usgN58H?= =?us-ascii?Q?tMnijVzI=2FB91sUGYnn0svE4QTqFLwayO0bg=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95486 Subject: [ruby-core:95486] [Ruby master Feature#16273] Proposal: Shorthand operator for "#instance_method" 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 #16273 has been reported by osyo (manga osyo). ---------------------------------------- Feature #16273: Proposal: Shorthand operator for "#instance_method" https://bugs.ruby-lang.org/issues/16273 * Author: osyo (manga osyo) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- hi, created issues to discuss shorthand for "#instance_method" ## Overview Ruby 2.7 adds a `#method` shorthand `.:` operator. * [Feature #12125: Proposal: Shorthand operator for Object#method - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/12125) * [Feature #13581: Syntax sugar for method reference - CommonRuby - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/13581) In this issues want to discuss the shorthand operator for "#instance_method". ## Background If you want to pass an array to `Array#zip` or `Hash#merge` as shown below, the code will be messy. ```ruby arrays = [["a", "b"], ["c"], ["d", "e"]] hashs = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}] # `#first` must be a receiver and the value excluding `#first` must be passed as an argument arrays.first.zip(*arrays.drop(1)) arrays.first.product(*arrays.drop(1)) hashs.first.merge(*hashs.drop(1)) ``` This can be solved by using `# bind_call` ([# 15955] (https://bugs.ruby-lang.org/issues/15955)). ```ruby arrays = [["a", "b"], ["c"], ["d", "e"]] hashs = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}] Array.instance_method(:zip).bind_call(*arrays) Array.instance_method(:product).bind_call(*arrays) Hash.instance_method(:merge).bind_call(*hashs) ``` But `#instance_method` is long. I'm thinking shorthand operator for `#instance_method`. :MEMO: There was a suggestion to add `Array.zip` or `Array.product` in the past * [Feature #8970: Array.zip and Array.product - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/8970) * [Feature #6499: Array::zip - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/6499) * [Feature #7444: Array#product_set - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/7444) ## Proposal new operator I can't come up with a suitable operator yet, sorry... However, considering the `.:` operator, I think "operator + Symbol (`:`)" is good. ```ruby # Document-like writing # `#` + operator Array#zip Array.#zip Array#:zip # Constant-link writing # :: + :hoge Array:::zip Array::#zip ``` Also, the following syntax is valid at this time, so it may be difficult to adopt. ```ruby Array!zip Array@zip Array&zip Array:zip ``` Please comment if you are interested in the shorthand operator for `# instance_method`. * Other `#instance_method` usecase * Proposal shorthand operator * etc... Thank you! :) -- https://bugs.ruby-lang.org/