With the latest release of ruby 1.9, blocks introduce their own scope. Below is the example.
x = 1
10.times do |u; x|
x =u
p "value of x - #{x}"
end
p "value of x - #{x}"
In the above case, x is treated as a local variable and we are assigning value of u to x in the loop.
Thank You,
x = 1
10.times do |u; x|
x =u
p "value of x - #{x}"
end
p "value of x - #{x}"
In the above case, x is treated as a local variable and we are assigning value of u to x in the loop.
Thank You,
No comments:
Post a Comment