From: Peter Vandenabeele Date: 2011-01-26T07:53:55+09:00 Subject: Re: The finer points of postfix conditionals. Robert Klemme wrote in post #977145: > On Mon, Jan 24, 2011 at 3:22 PM, Jon Leighton > wrote: ... >> and even: >> >> if false >> foo = 1 >> bar = 2 >> end >> >> (results in both foo and bar being assigned nil) > > This is not exactly true: foo is not "assigned nil" but rather is foo > initialized as a local variable and initially a variable refers nil. > There is no assignment but because you have an assignment in code > (even though it's no executed) the local variable comes into existence > (see above). To understand this better, I used the method 'defined?'. Would 'defined?' be a correct way to determine if a name was already 'initialized as a local variable' in this case? $ rvm use 1.9.2 # (same behavior in 1.8.7) Using /home/peterv/.rvm/gems/ruby-1.9.2-p136 $ irb 001:0> defined?(x) #=> nil 002:0> if false 003:1> x = 10 004:1> end #=> nil 005:0> defined?(x) #=> "local-variable" 006:0> x #=> nil Thanks, Peter -- Posted via http://www.ruby-forum.com/.