[Boulder Ruby Group] Fwd: Ruby 1.9 block scope change
Tim Pease
tim.pease at gmail.com
Thu Feb 28 14:39:43 EST 2008
On Feb 28, 2008, at 11:21 AM, Robert Campbell wrote:
> Forwarding this message from a friend on Santa Barbara's Ruby list...
>
>
> Begin forwarded message:
>
>> From: "P. Mark Anderson" <wayoutwest at gmail.com>
>> Date: February 28, 2008 10:25:41 AM MST
>> To: "Kyle Campos" <kcampos at bioiq.com>, "Aaron Campos" <acampos at bioiq.com
>> >, "Sean Porter" <sean at ideanode.com>, sbonrails at googlegroups.com,
>> "David Torres" <dtorres at bioiq.com>
>> Subject: Ruby 1.9 block scope change
>> Reply-To: sbonrails at googlegroups.com
>>
>> Rubyists,
>>
>> During this Matz talk at Google I learned that Ruby 1.9 has some new
>> features and many little incompatibilities to be aware of.
>>
>> http://www.youtube.com/watch?v=oEkJvvGEtB4
>>
>> Mark
>>
>> --~--~---------~--~----~------------~-------~--~----~
>> You received this message because you are subscribed to the Google
>> Groups "sbonrails" group.
>> To post to this group, send email to sbonrails at googlegroups.com
>> To unsubscribe from this group, send email to sbonrails-unsubscribe at googlegroups.com
>> For more options, visit this group at http://groups.google.com/group/sbonrails?hl=en
>> -~----------~----~----~----~------~----~------~--~---
>>
>> <local_scope_ruby_19.png>
The image has this bit of text in it ...
x = 15
loop {|x| x = 10; break}
p x #=> 15
And there is a warning about x being shadowed in the loop.
Because of this, I've started returning values from loops and
assigning them that way ...
x = 15
x = loop {|x| break 10}
p x #=> 10
This works in both 1.8 and 1.9 Just a good habit to get into. If
you've not played around with ruby1.9 yet, you can follow Bruce
William's instructions for installing 1.9 alongside 1.8.
<http://www.codefluency.com/articles/2007/12/02/it-s-time-to-play-with-1-9/
>
And I'm sure the talk by Matz is very interesting. Haven't had time to
watch it yet. Should put that on tomorrow afternoon's schedule.
Blessings,
TwP
More information about the Bdrg-members
mailing list