S
SpringFlowers AutumnMoon
I thought a iterator with a block is like an nameless function call...
so if it is a function call, the parameter is local.
but for the following, the output is surprising:
a = 1
p a
1.upto(10) {|a| p a}
p a
--------------
E:\>ruby test_iterator.rb
1
1
2
3
4
5
6
7
8
9
10
10
a is changed!
but is it true that the "a" is not global to begin with....
but then, isn't the "a" inside the block more local than the "a"
outside?
like in Pascal, i think there can be nested functions and therefore,
there will be local and then "local that is more local" than the outer
local.
so if it is a function call, the parameter is local.
but for the following, the output is surprising:
a = 1
p a
1.upto(10) {|a| p a}
p a
--------------
E:\>ruby test_iterator.rb
1
1
2
3
4
5
6
7
8
9
10
10
a is changed!
but is it true that the "a" is not global to begin with....
but then, isn't the "a" inside the block more local than the "a"
outside?
like in Pascal, i think there can be nested functions and therefore,
there will be local and then "local that is more local" than the outer
local.