Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld Talkback >> 960618

Pages: 1
Phrogz
Unregistered




0 is not a non-truth value!
      #34209 - 07/18/06 03:40 PM

The example adding the Fixnum#odd? method is incorrect. Unlike C or JavaScript or Java, 0 in Ruby is not a logical false value. Only the Boolean literal "false" and the value "nil" are non-truth values. The example code should be:

Code:
class Fixnum
def odd?
self % 2 == 1
end
end



Post Extras: Print Post   Remind Me!   Notify Moderator  
Anonymous
Unregistered




Re: 0 is not a non-truth value! [Re: Phrogz]
      #35685 - 08/23/06 11:52 AM

It should be added that falseness is not limited to the "nil" or "false" literals, but any objects that are instances of FalseClass or NilClass.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 1 anonymous users are browsing this forum.

Moderator:   

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 4317

Rate this topic

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5