Issue #4475 has been updated by bozhidar (Bozhidar Batsov).


I also dislike the use of `@` for this. It looks very weird and evokes strong references to instance variables in my mind. I'm not sure which characters exactly are an option, but I think we should avoid the use of `@`. Will something like `%1` work? (that's what Clojure uses, which `%` being the same as `%1`.

In general I question I lot the need for this and its usefulness, as short names are usually useful only in short blocks with 1/2 params, otherwise the readability of the code is impacted a lot. We already have a good shorthand for blocks with one param (at least in the most common case), so it feels to me we're complicated the parser/syntax without a very strong case for doing so. Many features are useful to some extent, but we should also keep in mind that none of them come for free. 

----------------------------------------
Feature #4475: default variable name for parameter
https://bugs.ruby-lang.org/issues/4475#change-77138

* 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>