7

In ruby, what does |= operator do?

Example:

a = 23
a |= 3333 # => 3351
konnigun
  • 1,777
  • 2
  • 16
  • 30

2 Answers2

10

The single vertical bar is a bitwise OR operator.

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

revolver
  • 2,334
  • 5
  • 22
  • 40
9

|= is called syntactic sugar.

In Ruby a = a | 3333 is the same as a |= 3333.

| means

Binary OR Operator copies a bit if it exists in either operand.Ruby Bitwise Operators

Arup Rakshit
  • 113,563
  • 27
  • 250
  • 306