From: indirect Date: 2022-01-16T02:20:10+00:00 Subject: [ruby-core:107142] [Ruby master Feature#15559] Logical XOR (^^) operator Issue #15559 has been updated by indirect (Andr�� Arko). mrkn (Kenta Murata) wrote in #note-1: > I think `^^` can be useful for the case that both `expr1` and `expr2` are not boolean. > Have you ever write such conditional expressions? Yes. Here is an example I encountered today. I have a class initializer that takes one argument: `Foo.new(bar)`. Perhaps it looks like this: ``` ruby class Foo def initialize(bar) @bar = bar end end ``` I want to add another kind of initialization, with a keyword: `Foo.new(baz: baz)`. That means I must allow `bar` to be nil. But I want to have only one of `bar` or `baz`. It is an error to provide both. Neither argument can be a boolean. ```ruby class Foo def initialize(bar = nil, baz: nil) raise ArgumentError unless bar ^^ baz @bar = bar || process_baz(baz) end end ``` ---------------------------------------- Feature #15559: Logical XOR (^^) operator https://bugs.ruby-lang.org/issues/15559#change-95990 * Author: baweaver (Brandon Weaver) * Status: Open * Priority: Normal ---------------------------------------- Currently we have bitwise `&` and logical `&&`, and bitwise `|` and logical `||`. Would it be possible to have logical `^^` in addition to the bitwise `^` for XOR? -- https://bugs.ruby-lang.org/ Unsubscribe: