Is it better to use obj.nil? or obj == nil and what are the benefits of both?
Is it better to use obj.nil? or obj == nil and what are the
Share
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.
It is exactly the same.It has the exact same observable effects from the outside ( pfff ) *If you like micro optimizations all the objects will return
falseto the.nil?message except for the objectnilitself, while the object using the==message will perform a tiny micro comparisonwith the other object to determine if it is the same object.
* See comments.