Feature #15559
openLogical XOR (^^) operator
Description
Currently we have bitwise &
and logical &&
, and bitwise |
and logical ||
. Would it be possible to have logical ^^
in addition to the bitwise ^
for XOR?
Updated by mrkn (Kenta Murata) about 2 years ago
You can write expr1 ^^ expr2
as !expr1 != !expr2
in the current Ruby.
If both expr1
and expr2
are boolean, you can write expr1 != expr2
.
I think ^^
can be useful for the case that both expr1
and expr2
are not boolean.
Have you ever write such conditional expressions?
Updated by mrkn (Kenta Murata) about 2 years ago
I think !=
is easier to understand than ^^
.
Updated by mame (Yusuke Endoh) about 2 years ago
Would it be possible to have logical ^ in addition to the bitwise ^ for XOR?
I think it is possible, but we need a good reason to do so. Do you have any use case?
Updated by sawa (Tsuyoshi Sawada) about 2 years ago
Unlike &&
and ||
, which involve short-circuit evaluation, and hence are keywords rather than methods, the proposed ^^
will not involve short-circuit evaluation. Which is the intended proposal: as a keyword, or as a method?