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=-4.1 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, 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 BD5051F453 for ; Fri, 8 Feb 2019 16:55:31 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 83486121B01; Sat, 9 Feb 2019 01:55:28 +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 C4633121B01 for ; Sat, 9 Feb 2019 01:55:25 +0900 (JST) Received: by filter0036p3las1.sendgrid.net with SMTP id filter0036p3las1-3516-5C5DB47B-25 2019-02-08 16:55:23.610874048 +0000 UTC m=+251925.321320265 Received: from herokuapp.com (ec2-100-27-20-2.compute-1.amazonaws.com [100.27.20.2]) by ismtpd0031p1iad2.sendgrid.net (SG) with ESMTP id CtpAYcd-Rsyq_-JcrxTWKA for ; Fri, 08 Feb 2019 16:55:23.523 +0000 (UTC) Date: Fri, 08 Feb 2019 16:55:24 +0000 (UTC) From: merch-redmine@jeremyevans.net To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66951 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 4475 X-Redmine-Issue-Author: jordi X-Redmine-Issue-Assignee: matz X-Redmine-Sender: jeremyevans0 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: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS6Ua2dTxCUiPm7Q1pAh5P1A1TFG4nabdvDOvG B5xu4OhFpKO/ZI3XCek70LxmwljFVj60cgS/xN25b9FIbmAgDNs9KX0dk+M2L2TnkJNCXJiDOV5oJK 8gktpYt/XvVICFTyR0FDVZHRuZzfIYGrjk4qEhQW2HLkG/TN1r46g+LSoQ== X-ML-Name: ruby-core X-Mail-Count: 91498 Subject: [ruby-core:91498] [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 jeremyevans0 (Jeremy Evans). janfri (Jan Friedrich) wrote: > So my preferred syntax for Ruby would be: > > ```ruby > [1, 2, 3].map { &1 + 2 } # => [3, 4, 5] > [1, 2, 3].reduce { &1 + &2 } # => 6 > ``` > > But I'm not sure if this could be realized without syntax conflicts. The problem with that is the syntax can be valid Ruby already, so it could break backwards compatibility: ```ruby class Integer def to_proc proc{|v| self + v} end end [1,2,3].map{|x| ([x]*2).map(&1 + 2)} ``` ---------------------------------------- Feature #4475: default variable name for parameter https://bugs.ruby-lang.org/issues/4475#change-76758 * Author: jordi (jordi polo) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * 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/