Skip to content

Latest commit

 

History

History
33 lines (21 loc) · 556 Bytes

Style-BitwisePredicate.md

File metadata and controls

33 lines (21 loc) · 556 Bytes

Pattern: Missing use of bitwise predicate

Issue: -

Description

Prefer bitwise predicate methods over direct comparison operations.

Examples

# bad - checks any set bits
(variable & flags).positive?

# good
variable.anybits?(flags)

# bad - checks all set bits
(variable & flags) == flags

# good
variable.allbits?(flags)

# bad - checks no set bits
(variable & flags).zero?

# good
variable.nobits?(flags)

Further Reading