but I was under the impression that && would stop as soon as it found the first false?
You are correct. But that didn't happen in your either of the examples.
In your both example 'O'
and 'X'
, are string objects, which has truthy value.
In the example ('X' && 'O') == 'X'
, ('X' && 'O')
gives "O"
, and it is being compared to "X"
, which is false
of-course. Thus you got false
.
In other one ('O' && 'X') == 'X'
, ('O' && 'X')
gives "X"
, and which is then being compared to "X"
, and of-course it should be true
. Thus you got true
in your PRY
.
Note : In Ruby all objects has truthy value, except nil
and false
.
While using &&
, it will be continuing evaluation, all its expression, till it is getting an expression which evaluated as falsy.