From: matt@... (matt neuburg) Date: 2008-01-26T11:44:56+09:00 Subject: Re: why must I initialize this variable? 7stud -- wrote: > Gary Wright wrote: > > Execution isn't moving backwards. You have to think of it as a two > > step process, parsing then execution. The parser is going to prepare: > > > > puts "#{hi}" if (hi = "hello") > > puts hi > > > > is such a way that the execution step sees: > > > > if (hi = "hello") > > puts "#{hi}" > > end > > puts hi > > > > So during execution, nothing is going backwards. But the parser has > > already tagged various parts of the code such that the 'hi' token in > > the conditional is an local variable assignment from a literal (thus > > the warning), the 'hi' token in the then clause as a method call, and > > the 'hi' token on the final puts as a local variable. > > > > These three issues > > 1) 0-argument method calls and local variables > > are syntactically identical > > 2) local variables don't have to be declared. > > 3) Ruby's if/unless modifiers imply execution > > order that is backwards from textual order > > > > Thanks for the detailed explanation. :) > > > Another corner case is > > Yep, I already know about that one. Thanks to all who contributed to this explanation - it's exactly what I wanted to know. m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Leopard - http://www.takecontrolbooks.com/leopard-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com