+ 3

Ruby - Why is output 2 and not 3?

x = 0 y = 1 puts x == y ? y : (x ? 2 : 3) I expect: x is different from y, so instead of putting out y, expression in parentheses is evaluated; since x is 0, 3 should be outputted. Why is 2 instead?

2nd Feb 2020, 10:57 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
1 Odpowiedź
+ 4
In ruby zero value is not false like c++ for example.
2nd Feb 2020, 11:11 PM
Black Winter