From: Ale Miralles Date: 2019-02-07T09:48:26-03:00 Subject: [ruby-core:91470] Re: [Ruby trunk Feature#4475] default variable name for parameter --===============2141552006== Content-Type: multipart/alternative; boundary="00000000000055e55905814d44c1" --00000000000055e55905814d44c1 Content-Type: text/plain; charset="UTF-8" Kotlin has it, too. It's a nice feature. In a pet language of mine, I added the index as an "implicit" argument, too. Something like this: elements = ["foo", "bar", "baz"] elements.each { puts "Element at index #{idx} has value #{it}." } "Element at index 0 has value foo." "Element at index 1 has value bar." etc.... I think it would be handy to have that in Ruby. ~ Ale Miralles. http://amiralles.com.ar On Thu, Feb 7, 2019 at 4:36 AM wrote: > Issue #4475 has been updated by matz (Yukihiro Matsumoto). > > > I still feel weird when I see `@` and `@1` etc. Maybe I will get used to > it after a while. > I need time. > > Matz. > > > ---------------------------------------- > Feature #4475: default variable name for parameter > https://bugs.ruby-lang.org/issues/4475#change-76718 > > * 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/ > > Unsubscribe: > > --00000000000055e55905814d44c1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Kotlin has it, too. It's a nice featu= re. In a pet language of mine, I added the=C2=A0index=C2=A0as an "impl= icit" argument, too. Something like this:

elements=C2=A0 =3D ["foo", "bar", "baz&qu= ot;]
elements.each=C2=A0{
=C2=A0 puts "Element at = index #{idx} has value #{it}."
}

&q= uot;Element at index 0 has value foo."
"Element at inde= x 1 has value bar."
etc....

I t= hink it would be handy to have that in Ruby.

~ Ale= Miralles.



On Thu, Feb 7, 2019 at 4:36 AM= <matz@ruby-lang.org> wrote= :
Issue #4475 ha= s been updated by matz (Yukihiro Matsumoto).


I still feel weird when I see `@` and `@1` etc. Maybe I will get used to it= after a while.
I need time.

Matz.


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

* Author: jordi (jordi polo)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
=3Dbegin

There is a very common pattern in Ruby:

=C2=A0object.method do |variable_name|
=C2=A0 variable_name doing something=C2=A0
=C2=A0end

=C2=A0Many 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 commo= n to see things like :

=C2=A0@my_sons.each { |s| s.sell_to_someone }

or

=C2=A0Account.all.each { |a|=C2=A0 my_account << a.money }


=C2=A0People 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:

=C2=A0 Account.all.each { my_account << it.money }

Where it is automagically filled and it doesn't need to be declared.=C2= =A0

I think it is as readable or more (for newbies who don't know what is |= |) and we save some typing :)


=3Dend




--
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=3Dunsubscribe= >
<http://lists.ruby-lang.org/cgi-bin/m= ailman/options/ruby-core>
--00000000000055e55905814d44c1-- --===============2141552006== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: --===============2141552006==--