From: ts Date: 2003-05-31T00:20:41+09:00 Subject: Re: local variable and local variable in block behave differently >>>>> "a" == ahoward writes: Well, it's more a> my best guess is that: a> 1.times do a> #### a> #### here we are in a block a> #### a> if false a> #### a> #### assignment is parsed but not executed, 'a' (block-local) is now nil a> #### a> a = "" at compile time, ruby see a block local variable 'a', this variable will be created (at runtime) at the first assignement a> else a> #### a> #### at this point, there is no 'a' in *scope*, only a block-local 'a' a> #### thus the following block creates a new block-local 'a' a> #### a> 1.times { a = "a" } at runtime this is the first assignement, and the variable is created inside the second block a> end a> #### a> #### these statements operate on the only symbol known as 'a' at this a> #### point, which happen to be the *first* block-local a. this is not the a> #### same thing as scope, since blocks do not introduce a new scope. a> #### a> puts defined? a # => local-variable(in-block) ruby say that it has seen a local variable at compile time a> puts a # => nil and in this block, the local variable was not assigned Guy Decoux