From: Shea Martin Date: 2007-04-06T02:40:07+09:00 Subject: Re: false or true == true .... WTF? Shea Martin wrote: > I have the following code: > [code] > templated = nreturns > 0 or nparams > 0 > puts "nreturns = #{nreturns}, nparams = #{nparams}, templated = > #{templated}" > has_returns = nreturns > 0 > has_params = nparams > 0 > templated2 = (nreturns or nparams) > puts "has_returns.class = #{has_returns.class}, has_params.class = > #{has_params.class}, templated2.class = #{templated2.class}" > puts "has_returns = #{has_returns}, has_params = #{has_params}, > templated2 = #{templated2}" > puts "" > [/code] > > when nreturns is 0 and nparams is 1 or more I get this output: > [output] > nreturns = 1, nparams = 0, templated = true > has_returns.class = TrueClass, has_params.class = FalseClass, > templated2.class = Fixnum > has_returns = true, has_params = false, templated2 = 1 > [/output] > > Both 'templated2' and 'templated' should be true, not 0. I can't seem > to duplicate this in irb. Even in the debugger, > "p nreturns > 0 or nparams > 0" gives true, while "p templated" gives > false. > > This must be a bug in the interpreter is my guess? My ruby version is > 1.8.4 win32. > > Thanks, > ~S I can get templated to the correct value by doing this: [code] templated = false if nreturns > 0 or nparams > 0 templated = true end [/code] But I should not have to do this. Annoying. ~S