From: Brian Candler Date: 2010-02-20T20:28:57+09:00 Subject: Re: Ruby conditionals subtlety? Maybe it's clearer like this: if false foo = 123 end puts foo # nil puts bar # undefined local variable or method 'bar' That is, for a bare word expression like 'foo' ruby has to decide whether to parse it as a method call - as foo() or self.foo - or as a local variable reference. It makes the decision based on whether there has been a previous assignment of the form "foo = ..." parsed earlier in the code. This is regardless of whether the code is actually executed, because we haven't started executing any of it yet. "earlier" in the code is strictly left-to-right. foo = 123 if not defined?(foo) At the point of defined?, "foo = ..." has already been seen, and so bareword foo is known to be a local variable, and therefore the symbol is 'defined' as a local variable at this point in the source code, whether or not an assignment has actually been made. -- Posted via http://www.ruby-forum.com/.