Found table http://phrogz.net/programmingruby/language.html#table_18.4 but unable to find description for |=
How the |=
assignment operator works?
Found table http://phrogz.net/programmingruby/language.html#table_18.4 but unable to find description for |=
How the |=
assignment operator works?
When working with arrays |= is useful for uniquely appending to an array.
>> x = [1,2,3]
>> y = [3,4,5]
>> x |= y
>> x
=> [1, 2, 3, 4, 5]
Bitwise OR assignment.
x |= y
is shorthand for:
x = x | y
(just like x += y
is shorthand for x = x + y
).
With the exception of ||=
and &&=
which have special semantics, all compound assignment operators are translated according to this simple rule:
a ω= b
is the same as
a = a ω b
Thus,
a |= b
is the same as
a = a | b
It is listed in the link you provided. It's an assignment combined with bitwise OR. Those are equivalent:
a = a | b
a |= b