* [ruby-core:37677] semicolon in block arg list
@ 2011-06-29 22:52 Ryan Davis
2011-06-30 10:47 ` [ruby-core:37685] " Adam Prescott
0 siblings, 1 reply; 2+ messages in thread
From: Ryan Davis @ 2011-06-29 22:52 UTC (permalink / raw
To: ruby-core
I found some online doco about 1.8 -> 1.9 changes that includes this gem:
> x = 1
> [2,3].each {|y;x| x = y }
> p x # => 1
It says that ';' declares 'x' as block local. 1.9 warns about the shadowed variable regardless of ',' vs ';', so is this new syntax meaningful at all? I've never seen it used anywhere.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [ruby-core:37685] Re: semicolon in block arg list
2011-06-29 22:52 [ruby-core:37677] semicolon in block arg list Ryan Davis
@ 2011-06-30 10:47 ` Adam Prescott
0 siblings, 0 replies; 2+ messages in thread
From: Adam Prescott @ 2011-06-30 10:47 UTC (permalink / raw
To: ruby-core
On Wed, Jun 29, 2011 at 11:52 PM, Ryan Davis <ryand-ruby@zenspider.com> wrote:
> I found some online doco about 1.8 -> 1.9 changes that includes this gem:
>
>> x = 1
>> [2,3].each {|y;x| x = y }
>> p x # => 1
>
> It says that ';' declares 'x' as block local. 1.9 warns about the shadowed variable regardless of ',' vs ';', so is this new syntax meaningful at all? I've never seen it used anywhere.
>
I'd say it's meaningful, given the difference in output here (on 1.9,
of course):
a = 1; [2].each { |a| p a }; a #=> 2; 1
a = 1; [2].each { |;a| p a }; a #=> nil; 1
a = 1; [2].each { |a| p a; a = 2; p a }; a #=> 2; 2; 1
a = 1; [2].each { |;a| p a; a = 2; p a }; a #=> nil; 2; 1
The final result is that a == 1 in each case, but inside the block,
the ; makes a difference.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-06-30 10:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-29 22:52 [ruby-core:37677] semicolon in block arg list Ryan Davis
2011-06-30 10:47 ` [ruby-core:37685] " Adam Prescott
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).