From: Brian Candler Date: 2003-05-30T23:21:52+09:00 Subject: Re: local variable and local variable in block behave differently On Fri, May 30, 2003 at 09:49:40PM +0900, Seb Clediere wrote: > I am sligthly surprised by this behaviour: > > if false > b = "" From this point, variable "b" is defined (even though the assignment is never executed, the interpreter has *parsed* an assignment) > else > 1.times { b = "b" } > end This assigns to variable 'b'. Because it already exists outside of the block, it assigns to this pre-existing variable, instead of bringing a temporary variable into existence just for the the lifetime of the block. > 1.times do > if false > a = "" > else > 1.times { a = "a" } > end > puts defined? a # => local-variable(in-block) > puts a # => nil > end OK, that's weird... I would have thought that the assignment to 'a' in the inner block would have bound to the 'a' brought into existence in the outer block, but it hasn't. Cheers, Brian.