Zero is true, but it isn't

If only you had any idea of how many times this was raised up and
explained. I hope you do not find it overly rude an unwelcome if I
suggest that you search the archive first at
http://www.ruby-talk.org/ruby/ruby-talk/index.shtml for relevant
discussions. It is a very good starting point in general.

Being nice ;-),
Gennady.

···

-----Original Message-----
From: John Johnson [mailto:johnatl@mac.com]
Sent: Wednesday, April 19, 2006 16:51
To: ruby-talk ML
Subject: Zero is true, but it isn't

I was wondering today, so I tried this:

puts "It's true" if 0

Which prints "It's true", meaning 0 is not false. (This
should surprise C/C++/etc. people).

So that means
puts "It's equal" if 0 == true

but 0 != true. Although it seems it should be, since 0 !=
false as well. So, by extension, if an object is not nil, and
it is not equal to false, then it would stand to reason that
it is equal to true.

Any thoughts?

Regards,
   JJ

---
Help everyone. If you can't do that, then at least be nice.

I'll try that when the server is back up.

I thought I had an original thought. Oh well.

Regards,
   JJ

···

On 19-Apr-2006, at 19:59, Gennady Bystritsky wrote:

If only you had any idea of how many times this was raised up and
explained. I hope you do not find it overly rude an unwelcome if I
suggest that you search the archive first at
http://www.ruby-talk.org/ruby/ruby-talk/index.shtml for relevant
discussions. It is a very good starting point in general.

Being nice ;-),
Gennady.

-----Original Message-----
From: John Johnson [mailto:johnatl@mac.com]
Sent: Wednesday, April 19, 2006 16:51
To: ruby-talk ML
Subject: Zero is true, but it isn't

I was wondering today, so I tried this:

puts "It's true" if 0

Which prints "It's true", meaning 0 is not false. (This
should surprise C/C++/etc. people).

So that means
puts "It's equal" if 0 == true

but 0 != true. Although it seems it should be, since 0 !=
false as well. So, by extension, if an object is not nil, and
it is not equal to false, then it would stand to reason that
it is equal to true.

Any thoughts?

Regards,
   JJ

---
Help everyone. If you can't do that, then at least be nice.

---
Help everyone. If you can't do that, then at least be nice.