From: Rick DeNatale Date: 2010-08-18T01:21:07+09:00 Subject: Re: question on if / defined?() On Tue, Aug 17, 2010 at 12:05 PM, Jedrin wrote: > assuming x is not defined, why does the statement > > x = true if !defined?(x) > > > produce x is nil ? Because x is defined, this happens at parse time so it doesn't matter if the assignment is executed or not. > > y = true if !defined?(x) > >  is no different Not by itself y = true if !defined? x y # => true I'm guessing you had this in a program AFTER something which defined x > > this however works fine: > > if !defined?(x) because at this point x is NOT defined since the parser hasn't yet seen it. >  x = true > end HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale