Inline helper to not pollute Ruby class definition
class Integer
def allbits?(mask)
- mask = rb_to_int(mask)
- self & mask == mask
+ if mask.respond_to?(:to_int)
+ mask = mask.to_int
+ return self & mask == mask
end
- def anybits?(mask)
- mask = rb_to_int(mask)
- !(self & mask).zero?
+ classname = mask.class
+ classname = mask.inspect if mask.nil? || mask.equal?(false) || mask.equal?(true)
+ raise TypeError, "no implicit conversion of #{classname} into #{self.class}"
end
- def nobits?(mask)
- mask = rb_to_int(mask)
- (self & mask).zero?
+ def anybits?(mask)
+ if mask.respond_to?(:to_int)
+ mask = mask.to_int
+ return !(self & mask).zero?
end
- private
-
- def rb_to_int(value)
- unless value.respond_to?(:to_int)
- value = case value
- when true, false
- value
- else
- value.class
+ classname = mask.class
+ classname = mask.inspect if mask.nil? || mask.equal?(false) || mask.equal?(true)
+ raise TypeError, "no implicit conversion of #{classname} into #{self.class}"
end
- raise TypeError, "no implicit conversion of #{value} into Integer"
+
+ def nobits?(mask)
+ if mask.respond_to?(:to_int)
+ mask = mask.to_int
+ return (self & mask).zero?
end
- value.to_int
+
+ classname = mask.class
+ classname = mask.inspect if mask.nil? || mask.equal?(false) || mask.equal?(true)
+ raise TypeError, "no implicit conversion of #{classname} into #{self.class}"
end
end
