From: Gavin Kistner Date: 2005-02-22T23:37:37+09:00 Subject: Re: Proposal for nil, 0, and "" in an if statement On Feb 22, 2005, at 7:32 AM, Gavin Kistner wrote: > On Feb 22, 2005, at 7:19 AM, Peter Hickman wrote: >>> I don't have actual code, but imagine looping through records >>> returned with financial data, and you want to print out a "-" if the >>> field is missing -or- zero. The whole "this field doesn't have any >>> meaningful information that contributes to the sum of the column" >>> spreadsheet thing. >>> >> Might this not cause trouble with databases. A database record >> (returned >> as a structure or object) would have NULL == nil for fields with no >> value which is not the same as a field with a definite value such as >> 0. > > Yes, there are many cases where you DO want to distinguish between nil > and 0. These cases are already handled by the current behavior of > Ruby. To be clear - the proposal is NOT to make Ruby act like one of the many other languages where "", 0 and friends are treated as non-truth values in boolean expressions. The proposal is simply to add an additional method to all that allows a programmer to treat them the same in the few cases where that is desirable.