-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am 03.08.2010 11:02, schrieb Eugen Ciur:
Look here
http://svn.ruby-lang.org/repos/ruby/tags/v1_9_1_0/NEWS
Since v 1.9.1 block arguments (in our case |num|) are always local,
i.e in 'each' block |num| will not conflict
with outer 'num' variable. In your machine you have 1.9.1 version.
Additionally, if you run ruby with warnings enabled, you get notified:
marvin@ikarus:~$ ruby -w
array = [1,2,3,4,5]
x = 1
num = 1
array.each{|num| puts num*20 + x}
- -:4: warning: shadowing outer local variable - num
puts num
21
41
61
81
101
1
marvin@ikarus:~$ ruby -v
ruby 1.9.1p429 (2010-07-02 revision 28523) [x86_64-linux]
marvin@ikarus:~$
Marvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla -
http://enigmail.mozdev.org/
iEYEARECAAYFAkxX5XwACgkQDYShvwAbcNksbQCfaq3nuXGd4OZNB3c1RGYeA2xS
2o0AoIfKBAfM8UttAfamaFxW9jwwJkOr
=orQI
-----END PGP SIGNATURE-----