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.8 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_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 1DCE020248 for ; Mon, 18 Mar 2019 11:42:58 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 1822A1210FF; Mon, 18 Mar 2019 20:42:53 +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 36B4A1208C7 for ; Mon, 18 Mar 2019 20:42:50 +0900 (JST) Received: by filter0139p3mdw1.sendgrid.net with SMTP id filter0139p3mdw1-4828-5C8F8438-E 2019-03-18 11:42:48.185822635 +0000 UTC m=+313063.263786950 Received: from herokuapp.com (unknown [3.90.163.81]) by ismtpd0006p1iad2.sendgrid.net (SG) with ESMTP id _9UrLREWQkGMv5Op21b5xA for ; Mon, 18 Mar 2019 11:42:47.991 +0000 (UTC) Date: Mon, 18 Mar 2019 11:42:48 +0000 (UTC) From: shevegen@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 67317 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 4475 X-Redmine-Issue-Author: jordi X-Redmine-Issue-Assignee: nobu 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?6lbdtOg4RDRLuxD00eQtQKgoNAsge5d4xND7cbMQd0zMk8MoALPJ73HrWzRMPA?= =?us-ascii?Q?nBcaUFFRUpFd204OJP4=2F0OPdE10K4XykhzJYw6a?= =?us-ascii?Q?Lrpr1mOH5SjMJEjNo4ntY8DOLv6V8kzYrYxs3ww?= =?us-ascii?Q?Ypg59qmc=2FC6nNG0NCE7YG9Y7cHmDYK1F75Atfgg?= =?us-ascii?Q?FHv1HeLo1U6RMaGvQMtb6joJ6zVD7Hmp+zw=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 91865 Subject: [ruby-core:91865] [Ruby trunk Feature#4475] default variable name for parameter 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 #4475 has been updated by shevegen (Robert A. Heiler). I think @1 @2 is ok, syntax-wise; it reminds me of $1 $2 for regex matching. The main two advantages I see is that it is short to type; and also easy to remember. There is only one thing that I would like to add and this came from examples I saw elsewhere; in that the suggestion seems to allow us to completely omit specifying parameters in blocks, like: collection.each {|a, b, c| } versus collection.each { } Can we use @1 @2 in both variants? I think I may have had a slightly similar suggestion to the one listed here above 8 years ago, but my thought was that we'd still have to specify the names to the parameter (variables), so I thought we would use something like: collection.each {|long_name_a, long_name_b, long_name_c| pp @1 pp @3 } I do not mind either way, by the way - but when it comes to documentation and also examples, I think it would help to mention it up front which variant(s) people could use. The best may be to allow flexibility in both variants, e. g. to specify the name of the parameters, but to also be able to omit it, while still being able to use the positional targeting here, such as through @1 @2 and so forth. And, if this is the case, to also give an example or two in the main documentation for this functionality. Thanks. ---------------------------------------- Feature #4475: default variable name for parameter https://bugs.ruby-lang.org/issues/4475#change-77134 * Author: jordi (jordi polo) * Status: Closed * Priority: Normal * Assignee: nobu (Nobuyoshi Nakada) * Target version: ---------------------------------------- =begin There is a very common pattern in Ruby: object.method do |variable_name| variable_name doing something end Many times in fact the name of the object is so self explanatory that we don't care about the name of the variable of the block. It is common to see things like : @my_sons.each { |s| s.sell_to_someone } or Account.all.each { |a| my_account << a.money } People tend to choose s or a because we have the class or the object name just there to remind you about the context. I would like to know if can be a good idea to have a default name for that parameter. I think it is Groovy that does something like: Account.all.each { my_account << it.money } Where it is automagically filled and it doesn't need to be declared. I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :) =end -- https://bugs.ruby-lang.org/