# False or true == true .... WTF?

**URL:** <https://www.ruby-forum.com/t/false-or-true-true-wtf/91221>\
**Category:** Ruby\
**Created:** [April 5, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/false-or-true-true-wtf/91221 "2007-04-05T19:36:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [April 5, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/false-or-true-true-wtf/91221/1 "2007-04-05T19:36:16Z")

</div>

I have the following code:

```auto
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 ""
```

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

---

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [April 5, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/false-or-true-true-wtf/91221/2 "2007-04-05T19:41:18Z")

</div>

Shea M. wrote:

> puts "has\_returns = #{has\_returns}, has\_params = #{has\_params},  
> [/output]  
> ~S  
> I can get templated to the correct value by doing this:

```auto
templated = false
if nreturns > 0 or nparams > 0
  templated = true
end
```

But I should not have to do this. Annoying.

~S

---

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [April 5, 2007, 8:01pm UTC](https://www.ruby-forum.com/t/false-or-true-true-wtf/91221/3 "2007-04-05T20:01:20Z")

</div>

On Apr 5, 1:33 pm, Shea M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have the following code:
> 
> [code]  
> templated = nreturns \> 0 or nparams \> 0  
> try:  
> 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)  
> Should this be:  
> templated2 = (has\_returns or has\_params) ??

With those changers i get:  
nreturns = 0, nparams = 1, templated =true  
has\_returns.class = FalseClass, has\_params.class =TrueClass,  
templated2.class = TrueClass  
has\_returns = false, has\_params = true,templated2 = true

Cheers  
Chris

---

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [April 5, 2007, 8:10pm UTC](https://www.ruby-forum.com/t/false-or-true-true-wtf/91221/4 "2007-04-05T20:10:20Z")

</div>

Hi,

Am Freitag, 06. Apr 2007, 02:40:07 +0900 schrieb Shea M.:

> I can get templated to the correct value by doing this:
> 
> ```auto
> templated = false
> > if nreturns > 0 or nparams > 0
> > templated = true
> > end
> ```

In

t = nr \> 0 or np \> 0

the binding is

(t = nr \> 0) or (np \> 0)

Use

t = nr \> 0 || np \> 0

Bertram

---

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [April 5, 2007, 7:47pm UTC](https://www.ruby-forum.com/t/false-or-true-true-wtf/91221/5 "2007-04-05T19:47:18Z")

</div>

Shea M. wrote:

> This must be a bug in the interpreter is my guess? My ruby version is  
> 1.8.4 win32.

irb(main):013:0\> p nreturns \> 0 or nparams \> 0  
false  
=\> true  
irb(main):014:0\> p nreturns \> 0 || nparams \> 0  
true  
=\> nil

C:\>ruby -v  
ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32]

–  
Phillip “CynicalRyan” Gawlowski  
[http://cynicalryan.110mb.com/](http://cynicalryan.110mb.com/)

Rule of Open-Source Programming #5:

A project is never finished.
