From: Dave Thomas Date: 2001-09-19T01:06:50+09:00 Subject: [ruby-talk:21338] Re: if before or if after? Paul Brannan writes: > (1) If I do this: > > x = '' if not defined?(x) > p x > > Then I get this: > > nil > > (2) But if I do this: > > if not defined?(x) then x = '' end > > Then I get this: > > "" > > (3) But, if I do this: > > x = '' if not defined?(x) > if not defined?(x) then x = '' end > p x > > Then I get this: > > nil > > What's going on here? Just seeing the assignment to 'x' defines it. In x = '' unless defined? x 'x' is defined by the assignment, so the assignment doesn't execute :) Dave