print (-1 == -1) and (myobj.nil?)
true
print (-1 == -1) && (myobj.nil?)
false
Note, myobj.nil? returns false
so, should not this always be false.
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.
Because they have different operator precedence.
The first evaluates as:
It prints true, because -1 == -1, then print returns nil and
nil and falseis nil.The second is equivalent to:
It prints (true && false), which is false, then print returns nil.