From: Dennis Newbold Date: 2002-03-30T11:18:07+09:00 Subject: Re: Now that's surprising. Your example, in a more verbose form is equivalent to: result = true result = if not result false else nil end or, equivalently, result = unless result false else nil end The problem is that the "else nil" is not visibly seen, but is implied by the semantics of the if statement, which, like any other expression, must return something as the result of its execution. Its compounded by the fact that in many languages, if / unless are not viewed as expressions, but as control statements.Many languages do things implicitly, such as constructors / destructors in C++, implicit code conversions in C, etc. Once you are used to them, you really don't even think about them much. I think we can be grateful the Ruby has very few "surprises" of this nature. I suggest that in the future, perhaps you can get in the habit of always explicitly specifying your own else clause when using the if statement as an expression. It also makes things more understandable for yourself and other readers of your code. For example, result = true result = unless result then false else true end FWIW. Dennis On Fri, 29 Mar 2002, Chris Gehlker wrote: > Does anyone else think that the following little program is an instance of > Ruby violating the POLS by producing nil? I can fix it by uncommenting the > commented line but I don't think that that should be required. > > def truthTest > result = true > result = false unless result > # return result > end > > p truthTest > > -- > There is, nevertheless, a certain respect and a general duty of humanity > that ties us, not only to beasts that have life and sense, but even to > trees and plants. -Michel de Montaigne, essayist (1533-1592) >