Forum: Ruby Operator Precedence Conundrum

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
102f1009d9eeae1588cbce2fb750be31?d=identicon&s=25 Ja S. (jgs)
on 2017-01-29 02:33
I don't get this:

2.4.0 :001 > (false && false ? false : true)
 => true


2.4.0 :002 > (false and false ? false : true)
 => false

Parentheses can be used to produce the intended result:

2.4.0 :003 > (false && (false ? false : true))
 => false

But still the first case makes no sense to me.  Short circuit evaluation
would seem to dictate that the first instance should return false.

Thanks in advance for any enlightenment.
3a81ced4012650ca2004c9bff7b18202?d=identicon&s=25 Ronald F. (rovf)
on 2017-01-31 15:45
The && operator has higher precedense than ?:

The and operator has lower precedence than ?:
This topic is locked and can not be replied to.