Permalink
Browse files

support Numeric#zero? and Numeric#nonzero?

  • Loading branch information...
takahashim committed Nov 20, 2015
1 parent 0e721ef commit 40a9700ef8fee2237e7675ce00063743687953b2
Showing with 22 additions and 0 deletions.
  1. +12 −0 mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb
  2. +10 −0 mrbgems/mruby-numeric-ext/test/numeric.rb
@@ -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 @@
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

0 comments on commit 40a9700

Please sign in to comment.