I get the following different results:
Test 1:
def myblock
x = 1
y = 1
yield(x)
[x, y]
end
myblock do |x|
y = 10
end
# => [1,1]
Test 2:
x = 1
y = 1
1.upto(2) do |x|
y = 20
end
[x,y]
# => [1,20]
Variables created outside the block are available in the block. Why are they so?