I
Iñaki Baz Castillo
Hi, I remember reading somewhere that the Ruby handling of block local=20
variables is deprecated and will be fixed, but for now it gives very anoyin=
g=20
behaviour. For example:
This is obvious and correct:
a)
=2D------------------
[1,2,3,4].each { |kk| kk=3Dtrue }
=3D> [1, 2, 3, 4]
kk
=3D> NameError: undefined local variable or method `kk' for main:Object
=2D------------------
But what about this???:
b)
=2D------------------
kk =3D false
[1,2,3,4].each { |kk| kk=3Dtrue }
=3D> [1, 2, 3, 4]
kk
=3D>true
=2D------------------
So, "kk" is defined as "false" and later in a block it's "true", but this=20
value must not be visible outside the block. In a) it doesn't occur (so OK)=
=20
but in b) is annoying, kk is finally "true" just because in a block it=20
was "true" and before it it was defined in top level.
IMHO it makes no sense at all. Is there any explanation for this last case?
Thanks for any comment about it.
=2D-=20
I=C3=B1aki Baz Castillo
variables is deprecated and will be fixed, but for now it gives very anoyin=
g=20
behaviour. For example:
This is obvious and correct:
a)
=2D------------------
[1,2,3,4].each { |kk| kk=3Dtrue }
=3D> [1, 2, 3, 4]
kk
=3D> NameError: undefined local variable or method `kk' for main:Object
=2D------------------
But what about this???:
b)
=2D------------------
kk =3D false
[1,2,3,4].each { |kk| kk=3Dtrue }
=3D> [1, 2, 3, 4]
kk
=3D>true
=2D------------------
So, "kk" is defined as "false" and later in a block it's "true", but this=20
value must not be visible outside the block. In a) it doesn't occur (so OK)=
=20
but in b) is annoying, kk is finally "true" just because in a block it=20
was "true" and before it it was defined in top level.
IMHO it makes no sense at all. Is there any explanation for this last case?
Thanks for any comment about it.
=2D-=20
I=C3=B1aki Baz Castillo