Found table http://phrogz.net/programmingruby/language.html#table_18.4 but unable to find description for |=
How the |=
assignment operator works?
Ruby has an or-equals operator that allows a value to be assigned to a variable if and only if that variable evaluates to either nil or false .
The bitwise OR assignment operator ( |= ) uses the binary representation of both operands, does a bitwise OR operation on them and assigns the result to the variable.
In Ruby assignment operator is done using the equal operator "=". This is applicable both for variables and objects, as strings, floats, and integers are actually objects in Ruby, you're always assigning objects.
In Ruby, the === operator is used to test equality within a when clause of a case statement. In other languages, the above is true. To my knowledge, Ruby doesn't have true operators, they are all methods which are invoked on the LHS of the expression, passing in the RHS of the expression.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With