From: Fuad Saud Date: 2013-09-24T15:27:22-03:00 Subject: [ruby-core:57352] Re: [ruby-trunk - Feature #4830] Provide Default Variables for Array#each and other iterators --001a11c25ee6a7d2f304e7254913 Content-Type: text/plain; charset=ISO-8859-1 I don't like this. The only thing that doesn't hurt so much would be something like scala's underscores for one parameter blocks, but I'm not really sure about those either. On Tuesday, September 24, 2013, alexeymuranov (Alexey Muranov) wrote: > > Issue #4830 has been updated by alexeymuranov (Alexey Muranov). > > > How should nested blocks behave? > > [[1, 2], [3, 4]].map { item.map { item + 1 } } > ---------------------------------------- > Feature #4830: Provide Default Variables for Array#each and other iterators > https://bugs.ruby-lang.org/issues/4830#change-41955 > > Author: lazaridis.com (Lazaridis Ilias) > Status: Assigned > Priority: Low > Assignee: matz (Yukihiro Matsumoto) > Category: core > Target version: next minor > > > for arrays: use "item" by default > for hashes: use "key" and "value" by default > > names = ["Jane", "Michele", "Isabella"] > names.each { |name| print name, "\n" } > names.each { print item, "\n" } > > contact = {name:"Jane", phone:"1234567"} > contact.each { |key, value| print key, ": ", value, "\n"} > contact.each { print key, ": ", value, "\n"} > > - > > The benefits are: > > * more compact code (without loosing clarity of the code). > * no repetitions ("names, name, name") in a one-liner with {} block > > This extension does not break any existent behaviour. > > > -- > http://bugs.ruby-lang.org/ > -- Fuad Saud twitter | linkedin| coderwall | github| --001a11c25ee6a7d2f304e7254913 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I don't like this. The only thing that doesn't hurt so much would b= e something like scala's=A0underscores for one parameter blocks, but I&= #39;m not really sure about those either.

On Tuesday, September 24, = 2013, alexeymuranov (Alexey Muranov) wrote:

Issue #4830 has been updated by alexeymuranov (Alexey Muranov).


How should nested blocks behave?

[[1, 2], [3, 4]].map { item.map { item + 1 } }
----------------------------------------
Feature #4830: Provide Default Variables for Array#each and other iterators=
https://bugs.ruby-lang.org/issues/4830#change-41955

Author: lazaridis.com (Lazaridis Ilias)
Status: Assigned
Priority: Low
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


for arrays: use "item" by default
for hashes: use "key" and "value" by default

names =3D ["Jane", "Michele", "Isabella"]
names.each { |name| print name, "\n" }
names.each { print item, "\n" }

contact =3D {name:"Jane", phone:"1234567"}
contact.each { |key, value| print key, ": ", value, "\n"= ;}
contact.each { print key, ": ", value, "\n"}

-

The benefits are:

* more compact code (without loosing clarity of the code).
* no repetitions ("names, name, name") in a one-liner with {} blo= ck

This extension does not break any existent behaviour.


--
http://bugs.ruby-l= ang.org/


--
Fuad Saud
<= div style=3D"text-align:left">


--001a11c25ee6a7d2f304e7254913--