Ryan Davis wrote:
> On Feb 18, 2010, at 13:44 , Farhad Farzaneh wrote:
> 
>>>> irb(main):002:0> unless defined?(fooo) ; fooo = true ; end
>> 
>> Cool, any chance you could give a short description for those of us that 
>> have never really thought about the parser or used parse_tree_show?
> 
> Your latter code snippet treats "fooo" in defined? as a method call. 
> This is because the assignment inside the conditional hasn't been parsed 
> yet, and hasn't affected the lookup tables.
> 
> The former doesn't have this problem because the body of the conditional 
> is parsed first.

Thanks. To make sure I understand:  In the first case,

> foo = true unless defined?(foo)

the parser encounters 'foo', adds it to the symbol table, and then sees 
the defined? call, so the net result is that foo is defined, but has nil 
value.  As such, if we're ever going to use defined? as a conditional, 
it should precede any other mention of the token (foo).

Is this correct?
-- 
Posted via http://www.ruby-forum.com/.