Why Ruby doesn't have some xor operator?

Hello,

#{subj} — not only (False|True|Nil)Class#^, but some general one, like
the and and or are. May be also ^^ with higher precedence.

P.

Pavel S. [email protected] writes:

Hello,

#{subj} — not only (False|True|Nil)Class#^, but some general one,
like the and and or are. May be also ^^ with higher precedence.

When would that be useful?

Pavel S. [email protected] writes:

Hello,

#{subj} — not only (False|True|Nil)Class#^, but some general one,
like the and and or are. May be also ^^ with higher precedence.

I’ll note that I find the “and” and “or” operators primarily useful
for the fact that they short-circuit (that is, the right hand side
doesn’t get evaluated unless it needs to be) and because they always
return one of their arguments.

Note that neither of those properties can hold with an xor operator.
You obviously can’t short-circuit, and secondly what do you return
when both arguments are true? nil or false?

On 15.08.2006 18:22, Pavel S. wrote:

Hello,

#{subj} — not only (False|True|Nil)Class#^, but some general one, like
the and and or are. May be also ^^ with higher precedence.

What semantic do you expect that operator to have? If you want it for
boolean XOR you can do

class Object
def ^(x) self && !x or !self && x end
end
=> nil

“roo” ^ false
=> true

“roo” ^ true
=> false

Fixnum still works

1 ^ 2
=> 3

Kind regards

robert