Class: Integer
Instance Method Summary collapse
-
#and?(other, test: :any) ⇒ Boolean
Tests common bits in
thisANDother. -
#and_all?(other) ⇒ Boolean
True if
thisANDotherisother. -
#and_any?(other) ⇒ Boolean
True if
thisANDotheris non-zero. -
#or?(other) ⇒ Boolean
True if
thisORotheris non-zero. -
#xor?(other) ⇒ Boolean
True if
thisXORotheris non-zero.
Instance Method Details
#and?(other, test: :any) ⇒ Boolean
Tests common bits in this AND other.
test:
:any => true if any bits are set
:all => true if all bits are set
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mug/bittest.rb', line 24 def and? other, test: :any case test.to_sym when :any and_any? other when :all and_all? other else raise ArgumentError, "invalid value for 'test' (given #{test.inspect}, should be :any or :all)" end end |
#and_all?(other) ⇒ Boolean
Note:
Similar to Integer#allbits? (Ruby 2.5+).
True if this AND other is other.
i.e. if all set bits in other are set in this.
70 71 72 73 |
# File 'lib/mug/bittest.rb', line 70 def and_all? other return false if other.zero? self & other == other end |
#and_any?(other) ⇒ Boolean
Note:
Similar to Integer#anybits? (Ruby 2.5+).
True if this AND other is non-zero.
i.e. if any set bits in other are set in this.
50 51 52 53 |
# File 'lib/mug/bittest.rb', line 50 def and_any? other return false if other.zero? self & other != 0 end |
#or?(other) ⇒ Boolean
Note:
No stdlib equivalent exists.
True if this OR other is non-zero.
88 89 90 |
# File 'lib/mug/bittest.rb', line 88 def or? other self | other != 0 end |
#xor?(other) ⇒ Boolean
Note:
No stdlib equivalent exists.
True if this XOR other is non-zero.
105 106 107 |
# File 'lib/mug/bittest.rb', line 105 def xor? other self ^ other != 0 end |