Commit 18190fa7 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #3030 from takahashim/nonzero

Support Numeric#zero? and Numeric#nonzero?
parents 0e721efe 40a9700e
......@@ -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
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment