Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112011-03-06T22:48:49ZRuby Issue Tracking System
Redmine Ruby master - Feature #4475 (Closed): default variable name for parameterhttps://bugs.ruby-lang.org/issues/44752011-03-06T22:48:49Zjordi (jordi polo)mumismo@gmail.com
<p>=begin</p>
<p>There is a very common pattern in Ruby:</p>
<p>object.method do |variable_name|<br>
variable_name doing something<br>
end</p>
<p>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 :</p>
<p>@my_sons.each { |s| s.sell_to_someone }</p>
<p>or</p>
<p>Account.all.each { |a| my_account << a.money }</p>
<p>People tend to choose s or a because we have the class or the object name just there to remind you about the context.</p>
<p>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:</p>
<p>Account.all.each { my_account << it.money }</p>
<p>Where it is automagically filled and it doesn't need to be declared.</p>
<p>I think it is as readable or more (for newbies who don't know what is ||) and we save some typing :)</p>
<p>=end</p>