From: Albert Wagner Date: 2002-03-30T00:32:04+09:00 Subject: Re: Now that's surprising. On Friday 29 March 2002 08:16 am, you 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 Yes, it can be surprising depending on what language(s) you are coming from. In some languages boolean expressions return either True or False. But in Ruby any value other than nil or false, is true. This leads to counter-intuitive gotchas like: irb(main):052:0> if true irb(main):053:1> end nil irb(main):054:0> if !true irb(main):055:1> end nil irb(main):056:0> if true irb(main):057:1> 'true' irb(main):058:1> end "true" irb(main):059:0> if !true irb(main):060:1> 'false' irb(main):061:1> end nil -- Quantum Mechanics: The dreams stuff is made of