In Ruby, why are the following lines true?
0 && 1 == 1 1 && 0 == 0 Why are they different and aren't both 0?
0 and 1 don't represent truth values in Ruby. In ruby anything that is not nil or false is true. If you add to this that:
The and and && operators evaluate their first operand. If false, the expression returns false; otherwise, the expression returns the value of the second operand.
You get that you evaluate true && true and then the result of the second operand is returned. If you wrote 3 && 4, you would have gotten 4!