If you do this:
$ nil
=> nil
But if you do this:
$ !nil
=> true
Why is !nil true?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you use a boolean operator like
!on an object in Ruby the object must first be converted, behind the scenes, to a boolean value (trueorfalse). Every object in Ruby is either “truthy” or “falsy,” and Ruby’s implementors have chosen fornilto be falsy, so!nilis equivalent to!false, which evaluates totrue.