# Operator |=

Hi,
I am trying to under this operator |=.Has anybody got some documentation
/ online link to explain this…

THnks
Chinna

On Feb 29, 2008, at 5:15 PM, Chinna K. wrote:

Hi,
I am trying to under this operator |=.Has anybody got some
documentation
/ online link to explain this…

THnks
Chinna

That’s one of the assignment operators:

a |= b

is the same as

a = a | b

with all the regular message sending semantics. Look for the | method
of the class of a.

-Rob

Chinna K. wrote:

Hi,
I am trying to under this operator |=.Has anybody got some documentation
/ online link to explain this…

THnks
Chinna

The number 10 written in binary format is:

8’s 4’s 2’s 1’s

1 0 1 0

The number 11 written in binary format is:

8’s 4’s 2’s 1’s

1 0 1 1

Assume 1 is equal to true and 0 is equal to false. Now OR each column
together:

## 1 0 1 0 1 0 1 1 OR

``````       <--result?
``````

In the first column(the leftmost column) you have (true OR true), which
is true, i.e you write 1 for the result:

## 1 0 1 0 1 0 1 1 OR

1 <–result?

In the second column, you have (false OR false), which is false, i.e you
write a 0 for the result:

## 1 0 1 0 1 0 1 1 OR

1 0 <–result?

In the third column, you have (true OR true), which is true:

## 1 0 1 0 1 0 1 1 OR

1 0 1 <–result?

In the last column, you have (false OR true) which is true:

## 1 0 1 0 1 0 1 1 OR

1 0 1 1 <–result?

What number is that?

8’s 4’s 2’s 1’s

1 0 1 1

1x8 + 0x4 + 1x2 + 1x1 = 11. So 10 | 11 is equal to 11.

The syntax a |= b is similar to the syntax a += 1. a += 1 is equivalent
to a = a + 1. So a |= b is equivalent to a = a | b. From the above you
should now know how to OR two numbers together: convert the numbers to
binary format and then OR the columns together.

x |= y is equivalent to x = x | y

On Sat, 01 Mar 2008 08:26:21 +0900, 7stud – [email protected]
wrote:

From the above you
should now know how to OR two numbers together: convert the numbers to
binary format and then OR the columns together.

Note that in ruby | is just a method. For integers it gives the result
of
bitwise or, but other classes define it differently. For instance,
Array
defines it to return set union, so [1] | [2] is [1,2].