G
Gavri Savio Fernandez
Hi,
I was going through matz's slides from the Ruby Conference 2003, and was checking out what the slides claimed was the most regrettable behaviour in ruby, namely that in the following code,
def foo
a = nil
ary.each do |b|
c = b
a = b
end
end
b and c are local to the each-block while the variable a which is referred to in the block is not. i assumed that in Ruby2, 'a' too would be local to the block and there would be different way to refer to the variable a which is outside the block's scope.
However, when i checked out the next slide, "Horror Of Horrors!" , in Ruby2, both a and c would be local to the entire method instead!
Now i'm just learning ruby, so i guess i'm missing something or have understood something wrong.
What i'd like to know is how is this new behaviour better than the old behaviour? Compared to Ruby2's rule, isn't the old rule more intuitive?
Gavri Savio Fernandez
___________________________________________
If only God would give me some clear sign! Like making a large deposit in my name at a Swiss bank. - Woody Allen
I was going through matz's slides from the Ruby Conference 2003, and was checking out what the slides claimed was the most regrettable behaviour in ruby, namely that in the following code,
def foo
a = nil
ary.each do |b|
c = b
a = b
end
end
b and c are local to the each-block while the variable a which is referred to in the block is not. i assumed that in Ruby2, 'a' too would be local to the block and there would be different way to refer to the variable a which is outside the block's scope.
However, when i checked out the next slide, "Horror Of Horrors!" , in Ruby2, both a and c would be local to the entire method instead!
Now i'm just learning ruby, so i guess i'm missing something or have understood something wrong.
What i'd like to know is how is this new behaviour better than the old behaviour? Compared to Ruby2's rule, isn't the old rule more intuitive?
Gavri Savio Fernandez
___________________________________________
If only God would give me some clear sign! Like making a large deposit in my name at a Swiss bank. - Woody Allen