From: ts Date: 2000-12-22T02:51:03+09:00 Subject: [ruby-talk:7895] Re: defined? problem? >>>>> "c" == craig duncan writes: c> if not defined? i for this line, ruby think that `i' is a method (`i' was never defined as a local variable before this statement) At runtime because the method `i' is not defined it will enter in the if and execute : c> i = 0 this time `i' make reference to a local variable (because you make an assignment) and is initialized at 0 c> end c> p i += 1 c> j = 0 if not defined? j At compile time, ruby resolve `j' as a reference (in the 2 cases) to a local variable, because `j = 0' was seen *before* `defined? j' At runtime, because `j' is a local variable, it is also defined and ruby don't execute the code `j = 0' this mean that j contain nil c> p j += 1 it give an error `+' is not defined for nil (i.e. `j') Guy Decoux