From: pascal.betz@... Date: 2019-03-22T06:56:31+00:00 Subject: [ruby-core:91923] [Ruby trunk Feature#4475] default variable name for parameter Issue #4475 has been updated by pascalbetz (Pascal Betz). gkemmey (Gray Kemmey) wrote: > Is there a reason to do this other than to save some typing? I'm not sure we've proposed any terribly real-world cases here where this made code better. Exactly my thought: Why? what will this make better or easier? IMHO it does exactly the opposite, it makes Ruby harder to read. By introducing @vars that are NOT instance vars. Code will be harder to read and understand (if it has an @ and starts with a number it is this, otherwise it is that). It saves some typing but short block-vars already possible now: ``` ruby each {|a| puts a} vs. each { puts @1 }) ``` I love ruby because it allows me to write concise and readable code. Naming variables is part of this. ---------------------------------------- Feature #4475: default variable name for parameter https://bugs.ruby-lang.org/issues/4475#change-77255 * 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/ Unsubscribe: