support Numeric#zero? and Numeric#nonzero?

This commit is contained in:
takahashim
2015-11-20 23:39:45 +09:00
parent 0e721efe9c
commit 40a9700ef8
2 changed files with 22 additions and 0 deletions
@@ -2,4 +2,16 @@ module Integral
def div(other)
self.divmod(other)[0]
end
def zero?
self == 0
end
def nonzero?
if self == 0
nil
else
self
end
end
end
+10
View File
@@ -16,3 +16,13 @@ end
assert('Float#div') do
assert_float 52, 365.2425.div(7)
end
assert('Integer#zero?') do
assert_equal true, 0.zero?
assert_equal false, 1.zero?
end
assert('Integer#nonzero?') do
assert_equal nil, 0.nonzero?
assert_equal 1000, 1000.nonzero?
end