What does a single vertical bar and an equal bar mean in Ruby?

In ruby, what does the |= operator do?

Example:

 a = 23 a |= 3333 # => 3351 
+4
source share
2 answers

The only vertical bar is the bitwise OR operator.

a |= 3333 equivalent to a = a | 3333 a = a | 3333

+9
source

|= called syntactic sugar.

In Ruby, a = a | 3333 a = a | 3333 same as a |= 3333 .

| means

The binary OR operator copies a bit if it exists in any of the operands. Bitwise Bitwise Operators

+7
source

Source: https://habr.com/ru/post/1490880/


All Articles