From: Lyle Johnson Date: 2001-03-08T00:10:09+09:00 Subject: [ruby-talk:12234] Re: Ruby API function to check for "true"-ness? > There's the RTEST macro. Yes, but as Shugo points out in another response to my question, RTEST returns "true" for some cases that I wouldn't expect it to (namely, an integer value of zero). But that's OK, that's the documented behavior for RTEST. I'm probably stuck in a Python mindset where the rules are a little different; I wrote a quick Ruby script to try a few tests: # Check the trueness of various objects in Ruby def test_veracity(obj) if obj puts("#{obj.type} with value [#{obj}] is true.") else puts("#{obj.type} with value [#{obj}] is false.") end end # Let's try a few examples test_veracity(true) test_veracity(false) test_veracity(nil) test_veracity(0) test_veracity(1) test_veracity(0.0) test_veracity(1.0) test_veracity("") test_veracity("anything") For this test, only the "nil" and "false" cases come back negative; everything else registers as true. I sort-of expected the "0", "0.0" and empty string cases to also come back false. It's not a bug or anything, just something I need to get used to!