Ruby - common pitfalls?

Is there a list of common pitfalls beginners in this language should
watch out for? I noticed (I just started with Ruby and it has almost
replaced Perl):

  • the if syntax. Pascal-style if is supported (and one is tempted to use
    it instead of the also supported C-style if since parantheses aren’t
    easy to enter on most keyboards), but comparisons have to be written
    in C style. Therefore this happened to me more than once:

    if foo = nil then
    # …
    end

    It’s getting even worse because nil is named ‘nil’, like it is in
    Pascal.

    The C-style syntax is:

    if (foo == nil)
    # …
    end

    and works perfectly. If only ( and ) were accessible without using the
    shift key…

  • accessing one character in a string.

    s[3] does not do what most programmers would expect:
    it returns a number. JavaScript is cleaner in this thing - there
    are both .charAt () and .charCodeAt (). IMHO s[n] should return the
    character as a string of length one, not the value - but now it’s
    too late to change this. The current meaning is not bad, it’s just
    unusual.
    s[3, 1] is to be used instead.

  • a %= b versus %=…=. A syntax highlighter gets into big trouble when
    seeing this construct. Nothing really seriuos, but I already had to
    insert “useless” comments to fix vim’s highlighting - which is unable
    to correctly highlight if-then-end expressions. Perhaps it would help
    to deprecate %=…= as string separator (any other character could be
    used with less problems).

BTW: what about this extension:

a, b += c, d

which would be equivalent to

a += c
b += d

and perfectly accepts list arguments:

*a += *b

Maybe even

*a = *b + *c

would be possible? Or perhaps instead:

a.zipWith! (b) do |x, y| x + y end # slightly resembling Haskell
a = b.zipWith © do |x, y| x + y end

which is a bit more verbose, but can be done with the current syntax.

Another idea for the above thing: an ArithArray class that is nearly
identical to the normal Array with one exception: the arithmetic and
logical operators work element-wise with the original meaning (so even
== would return a new array of true or false values).

···


[mpg123d] Just playing: …/01 cruel angel’s thesis - director’s edit - -ayanami-.mp3

Shinu no wa iya. Shinu no wa iya. Shinu no wa iya. Shinu no wa iya.
[Asuka in Neon Genesis Evangelion - english: “I don’t want to die”,

Note that you get warnings for this when using ruby -w

···

On Fri, Sep 27, 2002 at 06:37:23AM +0900, Rudolf Polzer wrote:

  • the if syntax. Pascal-style if is supported (and one is tempted to use
    it instead of the also supported C-style if since parantheses aren’t
    easy to enter on most keyboards), but comparisons have to be written
    in C style. Therefore this happened to me more than once:

    if foo = nil then
    # …
    end


Alan Chen
Digikata LLC
http://digikata.com

Hi,

···

Rudolf Polzer AntiATField_adsgohere@durchnull.de wrote:

Is there a list of common pitfalls beginners in this language should
watch out for? I noticed (I just started with Ruby and it has almost
replaced Perl):

I just offered my service to start compiling “Things That Newcomers to
Ruby Should Know” yesterday. Yours will be my first entries. Welcome!

  • the if syntax. Pascal-style if is supported (and one is tempted to use
    it instead of the also supported C-style if since parantheses aren’t
    easy to enter on most keyboards), but comparisons have to be written
    in C style. Therefore this happened to me more than once:
if foo = nil then
  # ...
end

It’s getting even worse because nil is named ‘nil’, like it is in
Pascal.

The C-style syntax is:

if (foo == nil)
  # ...
end

and works perfectly. If only ( and ) were accessible without using the
shift key…

I am sorry, I am not clear about this. In the “if foo = nil then”, is the
problem the “then” or the “=”? Also, you know, the parentheses are really
optional in the condition, independent of all other things.

  • accessing one character in a string.

s[3] does not do what most programmers would expect:
it returns a number. JavaScript is cleaner in this thing - there
are both .charAt () and .charCodeAt (). IMHO s[n] should return the
character as a string of length one, not the value - but now it’s
too late to change this. The current meaning is not bad, it’s just
unusual.
s[3, 1] is to be used instead.

Perfectly valid concern. I was also tripped by this a long time ago. It
took me a while to find the source of the problem.

  • a %= b versus %=…=. A syntax highlighter gets into big trouble when
    seeing this construct. Nothing really seriuos, but I already had to
    insert “useless” comments to fix vim’s highlighting - which is unable
    to correctly highlight if-then-end expressions. Perhaps it would help
    to deprecate %=…= as string separator (any other character could be
    used with less problems).

I am sorry, I am not clear about “%=…=”. (Maybe I am not a good
editor, after all?)

BTW: what about this extension:

(deleted)

which is a bit more verbose, but can be done with the current syntax.

Another idea for the above thing: an ArithArray class that is nearly
identical to the normal Array with one exception: the arithmetic and
logical operators work element-wise with the original meaning (so even
== would return a new array of true or false values).

These are all suggestions. I think you can implement the ArithArray class
yourself easily in Ruby.


[mpg123d] Just playing: …/01 cruel angel’s thesis - director’s edit - -ayanami-.mp3

Shinu no wa iya. Shinu no wa iya. Shinu no wa iya. Shinu no wa iya.
[Asuka in Neon Genesis Evangelion - english: “I don’t want to die”,


Hey, you like Neon Genesis Evangelion too? I really like the song. Right
now I am following DragonBall Z :slight_smile:

Cheers,

Bill

Hi,

  • the if syntax. Pascal-style if is supported (and one is tempted to use
    it instead of the also supported C-style if since parantheses aren’t
    easy to enter on most keyboards), but comparisons have to be written
    in C style. Therefore this happened to me more than once:

    if foo = nil then

    end

It’s getting even worse because nil is named ‘nil’, like it is in
Pascal.

Hmm, if you are Pascal addicted, you have to write

if foo = nil then
begin
# …
end

and should get syntax error. :wink:
It might be dangerous for Modula-2 users.

  • accessing one character in a string.

s[3] does not do what most programmers would expect:

May change in the future, due to M17N support.

  • a %= b versus %=…=. A syntax highlighter gets into big trouble when
    seeing this construct. Nothing really seriuos, but I already had to
    insert “useless” comments to fix vim’s highlighting - which is unable
    to correctly highlight if-then-end expressions. Perhaps it would help
    to deprecate %=…= as string separator (any other character could be
    used with less problems).

I admit Ruby syntax highlighter must be very smart.

*a = *b + *c

would be possible?

No way, I like the following

Or perhaps instead:

a.zipWith! (b) do |x, y| x + y end # slightly resembling Haskell
a = b.zipWith (c) do |x, y| x + y end

which is a bit more verbose, but can be done with the current syntax.

iff it has a better name than zipWith.

						matz.
···

In message “Ruby - common pitfalls?” on 02/09/27, Rudolf Polzer AntiATField_adsgohere@durchnull.de writes:

a = 0
1.upto(3) do |a|

some code

end

a is now 3

Iterators don’t introduce a new scope for previously defined variables. It’s
in the documentation but anybody who’s just learning “on the fly” will
certainly find this surprising. It’s my least favorite feature about Ruby
because while everything else feels right, it feels dead wrong(coming from
Perl’s lexical scoping rules).

···

Travis Whitton whitton@atlantic.net

Hello Rudolf,

Friday, September 27, 2002, 1:37:23 AM, you wrote:

Another idea for the above thing: an ArithArray class that is nearly
identical to the normal Array with one exception: the arithmetic and
logical operators work element-wise with the original meaning (so even
== would return a new array of true or false values).

do-it-yourself! :slight_smile: glorious APL days :slight_smile:

···


Best regards,
Bulat mailto:bulatz@integ.ru

There is a small list in Japanese. I have translated a few items to
Engrish on RWiki site. You can edit (append or correct) them :slight_smile:
http://rwiki.jin.gr.jp/cgi-bin/rw-cgi.rb?cmd=view;name=pitfall

– Gotoken

···

At Fri, 27 Sep 2002 06:37:23 +0900, Rudolf Polzer wrote:

Is there a list of common pitfalls beginners in this language should
watch out for? I noticed (I just started with Ruby and it has almost
replaced Perl):

  • a %= b versus %=…=. A syntax highlighter gets into big trouble when
    seeing this construct. Nothing really seriuos, but I already had to
    insert “useless” comments to fix vim’s highlighting - which is unable
    to correctly highlight if-then-end expressions. Perhaps it would help
    to deprecate %=…= as string separator (any other character could be
    used with less problems).

This was ‘fixed’ back in June. You can find the latest syntax file here:

http://mugca.its.monash.edu.au/~djkea2/vim/syntax/ruby.vim

Regards,
Doug

···

On Fri, Sep 27, 2002 at 06:37:23AM +0900, Rudolf Polzer wrote:

Scripsit ille Alan Chen alan@digikata.com:

···

On Fri, Sep 27, 2002 at 06:37:23AM +0900, Rudolf Polzer wrote:

  • the if syntax. Pascal-style if is supported (and one is tempted to use
    it instead of the also supported C-style if since parantheses aren’t
    easy to enter on most keyboards), but comparisons have to be written
    in C style. Therefore this happened to me more than once:

    if foo = nil then
    # …
    end

Note that you get warnings for this when using ruby -w

I know - but then the code already has been written. I think it just has
to be mentioned, not changed.


[mpg123d] Just playing: …/albums/feelwell/02 Don’t be discouraged.mp3
Erst lesen, dann posten.
Siehe auch 3d864c66$0$3247$a5ec1103@news.ilse.asys-h.de.
Danke an Juergen Ilse für diese ausführliche Erklärung.

Scripsit ille William Djaja Tjokroaminata billtj@y.glue.umd.edu:

Hi,

Is there a list of common pitfalls beginners in this language should
watch out for? I noticed (I just started with Ruby and it has almost
replaced Perl):

I just offered my service to start compiling “Things That Newcomers to
Ruby Should Know” yesterday. Yours will be my first entries. Welcome!

Thanks.


  • the if syntax. Pascal-style if is supported (and one is tempted to use
    it instead of the also supported C-style if since parantheses aren’t
    easy to enter on most keyboards), but comparisons have to be written
    in C style. Therefore this happened to me more than once:
if foo = nil then
  # ...
end

It’s getting even worse because nil is named ‘nil’, like it is in
Pascal.

The C-style syntax is:

if (foo == nil)
  # ...
end

and works perfectly. If only ( and ) were accessible without using the
shift key…

I am sorry, I am not clear about this. In the “if foo = nil then”, is the
problem the “then” or the “=”?

The problem is just that this if line is equal to Pascal’s:

if foo = nil then
begin
{ … }
end

Note that the first line is completely equal. When reading the above
code, I’m tempted to “parse” it as Pascal code and oversee the
assignment.

Also, you know, the parentheses are really
optional in the condition, independent of all other things.

The problem is just, that it:

  • looks better with the “then”
  • if the “then” is there, it looks like Pascal

But I just found a workaround (which already works):

if foo == nil; then # bash-like
# …
end

Maybe it’s less tempting to write a Pascal-style equality test if the if
syntax does not look exactly like Pascal.


  • accessing one character in a string.

s[3] does not do what most programmers would expect:
it returns a number. JavaScript is cleaner in this thing - there
are both .charAt () and .charCodeAt (). IMHO s[n] should return the
character as a string of length one, not the value - but now it’s
too late to change this. The current meaning is not bad, it’s just
unusual.
s[3, 1] is to be used instead.

Perfectly valid concern. I was also tripped by this a long time ago. It
took me a while to find the source of the problem.

Oh, in my “trap” it was relatively easy. I added the result to another
string and got an error since Ruby didn’t want to make a String of a
Fixnum. Good that Ruby does not do such automatic conversions.


  • a %= b versus %=…=. A syntax highlighter gets into big trouble when
    seeing this construct. Nothing really seriuos, but I already had to
    insert “useless” comments to fix vim’s highlighting - which is unable
    to correctly highlight if-then-end expressions. Perhaps it would help
    to deprecate %=…= as string separator (any other character could be
    used with less problems).

I am sorry, I am not clear about “%=…=”. (Maybe I am not a good
editor, after all?)

$ ruby -e ‘s = %=hello world=; p s;’
“hello world”
$ ruby -e ‘x = 3; x %= 2; p x;’
1

I’m not sure if it is always clear which meaning is the correct one. A
syntax highlighter would have to know…

$ ruby -e ‘x = 1; def x (s) p s; end; x %= 2; a = * 1’
$ ruby -e ‘x = 1; def x (s) p s; end; x %- 2; a - * 1’
" 2; a "

Seems like Ruby interprets %= as ‘operator%= (&a, b)’ whenever possible
when looking to the left.

But how to tell this to a syntax highlighter? At least %=…= and the
other %#…# rules would need different highlighting rules.


BTW: what about this extension:

(deleted)

which is a bit more verbose, but can be done with the current syntax.

Another idea for the above thing: an ArithArray class that is nearly
identical to the normal Array with one exception: the arithmetic and
logical operators work element-wise with the original meaning (so even
== would return a new array of true or false values).

These are all suggestions. I think you can implement the ArithArray class
yourself easily in Ruby.

It can easily be done - I think it would be ideal to add zipWith to the
normal Array class and then derive ArithArray from it, implementing the
“new” operators using zipWith.



[mpg123d] Just playing: …/01 cruel angel’s thesis - director’s edit - -ayanami-.mp3

Shinu no wa iya. Shinu no wa iya. Shinu no wa iya. Shinu no wa iya.
[Asuka in Neon Genesis Evangelion - english: “I don’t want to die”,


Hey, you like Neon Genesis Evangelion too?

Sou da.

I really like the song.

Me too - but IMHO the original version is the best one.

What a coincidence that the random signature fitted to the current
playlist item…

Right now I am following DragonBall Z :slight_smile:

BTW, this reminds me of a kakasi problem I have in my kakasi-renamer
script (which should rename file names containing Japanese characters to
Roumaji-encoded ones). I’ve opened a new thread for that.

···

Rudolf Polzer AntiATField_adsgohere@durchnull.de wrote:


[mpg123d] Just playing: …/albums/shamrock/09 don’t sigh.mp3

Menschen fürchteten die Dunkelheit, vertrieben sie mit Feuer…
[Rei in NGE, #11]

I must be missing something here, in perl I can do this:

$sum = 0;
for (0…10) { sum += $_; }

sum => 56

sum = 0
0.upto(10) { |i| sum += i }

sum => 56

I understand the value of local scoping in the blocks, but if I wanted
to access variables with external scope, how would you go about doing
that?

···

On Fri, Sep 27, 2002 at 08:38:22AM +0900, Travis Whitton wrote:

a = 0
1.upto(3) do |a|

some code

end

a is now 3

Iterators don’t introduce a new scope for previously defined variables. It’s
in the documentation but anybody who’s just learning “on the fly” will
certainly find this surprising. It’s my least favorite feature about Ruby
because while everything else feels right, it feels dead wrong(coming from
Perl’s lexical scoping rules).


Alan Chen
Digikata LLC
http://digikata.com

Hi,

I just created this list starting one hour ago. Not to create lengthy
discussions, please send any comment directly to me via e-mail. Thanks.

Regards,

Bill

Things That Newcomers to Ruby Should Know

···

=========================================

  1. Use “ruby -w” instead of simply “ruby” to get helpful warnings.

  2. The String#[Fixnum] method does not return the “character” (which is a
    string of length one) at the Fixnum position, but instead the character
    code at the position (however, this may change in the future). Currently,
    to get the character, use String#[Fixnum,1] instead.

  3. Be aware of the lexical scoping interaction between local variables and
    block local variables. If a local variable is already defined before the
    block, then the block will use (and quite possibly) modify the local
    variable; in this case the block does not introduce a new scope.

  4. In Ruby, there are two sets of logical operators: [!, &&, ||] and [not,
    and, or]. [!, &&, ||]'s precedence is higher than the assignments (=, %=,
    ~=, /=, etc.) while [not, and, or]'s precedence is lower. Also note that
    while &&'s precedence is higher than ||'s, the and’s precedence is the
    same as the or’s.

  5. In the case statement

    case obj
    when obj1

it is the “===” method which is invoked, not the “==” method. Also, the
order is “obj1 === obj” and not “obj === obj1”.

  1. Array.new (2, Hash.new) returns an array with two elements referencing
    the same, indentical hash, and not two independent hashes.

  2. After reading data from a file and putting them into variables, the
    data type is really String. To convert them into numbers, use the
    "to_i" or “to_f” methods. If you use the “+” operator to add the
    "numbers" without calling the conversion methods, for example, you will
    simply concatenate the strings.


matz@ruby-lang.org (Yukihiro Matsumoto) writes:

Or perhaps instead:

a.zipWith! (b) do |x, y| x + y end # slightly resembling Haskell
a = b.zipWith (c) do |x, y| x + y end

which is a bit more verbose, but can be done with the current syntax.

iff it has a better name than zipWith.

many languages use the “map” function for this. what about this:

module Enumerable
def map(*ls)
i = 0
collect{|e|
l = [e] + ls.collect{|l| l[i]}
i += 1
yield(*l)
}
end
end

p [1, 2].map([3, 4], [5, 6]){|a,b,c| a+b+c}
#=> [9, 12]

?

(http://merd.net/pixel/language-study/syntax-across-languages/BagAndLst.html#BagAndLstTrnTwoLstInPrl)

 * transform two lists in parallel
                                  
   map2                     OCaml 
   zipWith                  Haskell
   Zip                      Oz     
   map                      Dylan, Python, Scheme
   mapcar                   Common Lisp                                                           
   l1 with: l2 collect: ... Smalltalk     
   transform                C++
   ListPair.map             SML

Hi,

The list looks pretty good. Since the list in rwiki already started
earlier, should I just give my initial small list to it? My only question
is, how do we submit a new candidate for the list? (Also, please
translate the rest at your earliest convenience :slight_smile: Matz was absolutely
right; the next language to learn after Ruby should be Japanese :slight_smile: )

Also, I cannot help asking this question. Do people in Japan have their
own discussion group (in Japanese), in which case then the discussion in
comp.lang.ruby is only “half of the story”?

Regards,

Bill

···

===========================================================================
GOTO Kentaro gotoken@notwork.org wrote:

There is a small list in Japanese. I have translated a few items to
Engrish on RWiki site. You can edit (append or correct) them :slight_smile:
http://rwiki.jin.gr.jp/cgi-bin/rw-cgi.rb?cmd=view;name=pitfall

– Gotoken

Agreed… maybe the pitfall is not running with ruby -w during development :slight_smile:

···

On Fri, Sep 27, 2002 at 07:37:48AM +0900, Rudolf Polzer wrote:

Scripsit ille Alan Chen alan@digikata.com:

On Fri, Sep 27, 2002 at 06:37:23AM +0900, Rudolf Polzer wrote:

  • the if syntax. Pascal-style if is supported (and one is tempted to use
    it instead of the also supported C-style if since parantheses aren’t
    easy to enter on most keyboards), but comparisons have to be written
    in C style. Therefore this happened to me more than once:

    if foo = nil then
    # …
    end

Note that you get warnings for this when using ruby -w

I know - but then the code already has been written. I think it just has
to be mentioned, not changed.


Alan Chen
Digikata LLC
http://digikata.com

The problem is just that this if line is equal to Pascal’s:

if foo = nil then
begin
{ … }
end

Note that the first line is completely equal. When reading the above
code, I’m tempted to “parse” it as Pascal code and oversee the
assignment.

Also, you know, the parentheses are really
optional in the condition, independent of all other things.

The problem is just, that it:

  • looks better with the “then”
  • if the “then” is there, it looks like Pascal

But I just found a workaround (which already works):

if foo == nil; then # bash-like
# …
end

Maybe it’s less tempting to write a Pascal-style equality test if the if
syntax does not look exactly like Pascal.

Instead of finding “workarounds” to make Ruby look like Pascal or Bash, why not
just learn Ruby properly? Use -w always.


  • accessing one character in a string.

s[3] does not do what most programmers would expect:
it returns a number. JavaScript is cleaner in this thing - there
are both .charAt () and .charCodeAt (). IMHO s[n] should return the
character as a string of length one, not the value - but now it’s
too late to change this. The current meaning is not bad, it’s just
unusual.
s[3, 1] is to be used instead.

This is a good point. Did you know that where you expect to write

if string[3] == “e”

you can write

if string[3] == ?e

or

if string[3].chr == “e”

so all is not lost.


  • a %= b versus %=…=. A syntax highlighter gets into big trouble when
    seeing this construct. Nothing really seriuos, but I already had to
    insert “useless” comments to fix vim’s highlighting - which is unable
    to correctly highlight if-then-end expressions. Perhaps it would help
    to deprecate %=…= as string separator (any other character could be
    used with less problems).

So use another character.

Cheers,
Gavin

···

----- Original Message -----
From: “Rudolf Polzer” AntiATField_adsgohere@durchnull.de

Hi –

[ I tried to write by private email as you’d asked, but:

… while talking to mx.glue.umd.edu.:

MAIL From:dblack@candle.superlink.net
<<< 550 5.0.0 Sorry,no access for this domain
554 5.0.0 Service unavailable
]

  1. Array.new (2, Hash.new) returns an array with two elements referencing
    the same, indentical hash, and not two independent hashes.

Also if you don’t close the space before the (, you’ll get a warning
(at least with -w). The whole whitespace-before-parens thing might be
worth an entry of its own.

  1. After reading data from a file and putting them into variables, the
    data type is really String. To convert them into numbers, use the
    “to_i” or “to_f” methods. If you use the “+” operator to add the
    “numbers” without calling the conversion methods, for example, you will
    simply concatenate the strings.

You can use the new scanf to get around this. I don’t know whether
references to library stuff is outside the scope of what you want to
cover/include here – but anyway, just in case, its home is:
http://www.rubyhacker.com/code/scanf.

David

···

On Fri, 27 Sep 2002, William Djaja Tjokroaminata wrote:


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

In Perl, you access the outer scope unless you explicitly request a
locally scoped variable of the same name, using ‘my’.

What Travis is saying feels wrong to him is that the Ruby behaviour is
not uniform: you access and change the value of the variable in the
outer scope if a variable with the same name has already been defined,
but you create a locally scoped variable if the outer scope contains
no such variable.

I have to say that this still feels odd to me after nine months of
Ruby coding. Once you know about it, you can take it into account, but
anyone not learning the language from a book is likely to get caught
out by this.

Ian

···

On Fri 27 Sep 2002 at 08:51:05 +0900, Alan Chen wrote:

On Fri, Sep 27, 2002 at 08:38:22AM +0900, Travis Whitton wrote:

Iterators don’t introduce a new scope for previously defined variables. It’s
in the documentation but anybody who’s just learning “on the fly” will
certainly find this surprising. It’s my least favorite feature about Ruby
because while everything else feels right, it feels dead wrong(coming from
Perl’s lexical scoping rules).

I must be missing something here, in perl I can do this:

$sum = 0;
for (0…10) { sum += $_; }

sum => 56

sum = 0
0.upto(10) { |i| sum += i }

sum => 56

I understand the value of local scoping in the blocks, but if I wanted
to access variables with external scope, how would you go about doing
that?


Ian Macdonald | Ha. For once you’re both wrong but not
ian@caliban.org | where you are thinking. - Larry McVoy to
> Linus Torvalds on linux-kernel
>
>

When documenting or discussing ruby code, where did the “#” notation
for separating class and method come from? (I.e., String#length)

I’ve seen “.” and “::” before, but “#” is a new one on me.

Also, what’s the heritage of “yield”, smalltalk?

···

=====

Use your computer to help find a cure for cancer: http://members.ud.com/projects/cancer/

Yahoo IM: michael_s_campbell


Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

I understand the value of local scoping in the blocks, but if I wanted
to access variables with external scope, how would you go about doing
that?

In Perl you have a choice:

External scope

$sum = 0;
for (0…10) { $sum += $_; }
print “$sum\n”;

Use a new scope

$sum = 0;
for (0…10) { my $sum += $_; }
print “$sum\n”;

From perldoc:
The “my” keyword declares the listed variable to be local (lexically) to
the enclosing block, file, or “eval”.

The surprising thing about the Ruby version is that it only creates a locally
scoped variable if an external variable of the same name doesn’t exist. It
would be more natural if the block introduced a local variable to the block
by default and there was some other facility to use the external variable.
I don’t think matz wants to break backward compatibility, so I doubt this
will change. There are some interesting comments on rubygarden.org regarding
this problem, and I like the suggestion of using <> to locally scope a variable.

a = 0
1.upto(3) do

some code

end

a is now 0

However, judging by this poll

it looks like most people would like the default behaviour to be that variables
inside of || to be local.

···

Travis Whitton whitton@atlantic.net