>>>>> "G" == GOTO Kentaro <gotoken / math.sci.hokudai.ac.jp> writes:

G> As you see, in the formar case, |i| is shared with the outer scope.  
G> A significant use of this feature can be given:

G>   a = [4,5,6,3]
G>   sum = 0  
G>   a.each{|i| sum += i}
G>   p sum

 Well it's not really a use of this feature, because sum is not defined
between | |. Only i is between | | and in this case :
  * sum is a local variable
  * i is a dynamic variable

 My problem is that I've written something like this :

  i = 12
# add here some lines
  sum = 0
  a.each {|i| sum += i}
# add here some lines
  p i

 and I've lost my old value for i

G> In the book ``Object oriented scripting language Ruby'' (in Japanese), 
G> scopes of local variables are illustrated as follows:

 Apparently ruby has local_vars and dyna_vars.


G>     local2 = 88   # # #<-- scope of local1,local2

 local variable

G>                   # # #
G>     loop do       # # #
G>       local3 = 99 # # # #<-- scope of local3

 dynamic variable only if local3 is not a local variable of baz

G>       .....       # # # #


Guy Decoux