7

In ruby, what does |= operator do?

Example:

a = 23
a |= 3333 # => 3351
konnigun
  • 1,797
  • 2
  • 17
  • 30

2 Answers2

10

|= 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
  • 116,827
  • 30
  • 260
  • 317
10

The single vertical bar is a bitwise OR operator.

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

revolver
  • 2,385
  • 5
  • 24
  • 40