From: Josh Cheek Date: 2009-12-23T18:21:55+09:00 Subject: Re: newbie: if is not null else... --000e0cd112460a6853047b61d7a0 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Dec 22, 2009 at 7:53 AM, Alfonso Caponi wrote: > Thank you very much Rick. Using: > > x = '-' if x.nil? > > I've x = Null again.. :( > x should not be Null at this point. First, Null doesn't exist, in Ruby it is nil. Second, if you are using nil, then this should do what you want x = nil x = '-' if x.nil? x # => "-" x = 'abc' x = '-' if x.nil? x # => "abc" It seems works with > > if (x.to_s =~ /Null/) > x = '-' > end > > but I don't think is the best way to write it :( > That probably isn't doing what you think / want. Since Null should be nil, the only way that should match is if your class somehow returns a string with 'Null' in it. That seems pretty unlikely. I think Rick's answer is probably what you are looking for, but if an empty string evaluates to false in php, then you will need to add the condition for that, ie x = '-' if !x || x.empty? This assumes that x is expected to be a string, or nil. You should look at your code and make switch out your 'Null' with 'nil' , and if this hasn't solved your issue, perhaps explain what you are trying to do, ie give a series of different inputs, and what you want it to do to them. --000e0cd112460a6853047b61d7a0--