From: Adam Prescott Date: 2011-06-10T22:32:23+09:00 Subject: [ruby-core:36924] Re: [Ruby 1.9 - Feature #4830] Provide Default Variables for Array#each and other iterators --20cf301cc3c267552b04a55b99c1 Content-Type: text/plain; charset=UTF-8 On Fri, Jun 10, 2011 at 1:28 AM, Jan Lelis wrote: > "string".gsub(/com(plex)_reg(ex)/){ > # use $1, $2, ... > } > > To get back to the original problem, I'd prefer: $item (which is -of > course- not a global variable). > > PS: Since $dollar variables are rarely used anyway, lets transform them all > into special variables :D > I think the ${1,2,3,...} variables match the gsub(regex, "a $1 replacement $2 here $3"). While using $item, or any other identifier, as the implicit argument might make some code a few characters shorter to write, what other benefits are there? All I can see is that it adds one more thing to learn in the language and introduces greater complexity, both for people who've never seen it, and for scoping rules. I see nothing wrong with the explicit { |item| ... }. It's readable, it works. --20cf301cc3c267552b04a55b99c1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Fri, Jun 10, 2011 at 1:28 AM, Jan Lelis <mail@janlelis.de&g= t; wrote:
"string".gsub(/com(plex)_reg(ex)/){
=C2=A0# use $1, $2, ...
}

To get back to the original problem, I'd prefer: $item (which is -of co= urse- not a global variable).

PS: Since $dollar variables are rarely used anyway, lets transform them all= into special variables :D

I think the ${1,2= ,3,...} variables match the gsub(regex, "a $1 replacement $2 here $3&q= uot;).

While using $item, or any other identifier,= as the implicit argument might make some code a few characters shorter to = write, what other benefits are there? All I can see is that it adds one mor= e thing to learn in the language and introduces greater complexity, both fo= r people who've never seen it, and for scoping rules. I see nothing wro= ng with the explicit { |item| ... }. It's readable, it works.
--20cf301cc3c267552b04a55b99c1--