Method: Integer#bitmask

Defined in:
lib/core/facets/integer/bitmask.rb

#bitmask(mask) ⇒ Object

Apply a bitmask.

1.bitmask(6) #=> 7

Using a inverted bitmask clears bits.

7.bitmask(~2) #=> 5
5.bitmask(~2) #=> 5

CREDIT: George Moschovitis



59
60
61
62
63
64
65
# File 'lib/core/facets/integer/bitmask.rb', line 59

def bitmask(mask)
  if mask < 0
    self & mask
  else
    self | mask
  end
end