From: Gary Wright Date: 2008-01-25T02:11:10+09:00 Subject: Re: why must I initialize this variable? On Jan 24, 2008, at 4:38 AM, 7stud -- wrote: > > So the parser marks hi as a method before the code hi="hello" is > parsed, > and thereafter hi is marked as a variable? Then execution evaluates > hi="hello" and thereafter execution moves *backwards* to execute puts > hi? 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 when considered separately are quite nice, but when combined, have some awkward corner cases. You could get rid of the problem by: a) forcing all 0-arg method calls to be self.method or method() b) requiring temporary variables to be declared c) eliminating if/unless modifiers d) implementing more elaborate multi-pass parser