mirror of
https://github.com/github/rails.git
synced 2026-05-04 03:00:06 -04:00
Let Integer#multiple_of? accept zero as argument
[#2982 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
committed by
Jeremy Kemper
parent
8571aa613f
commit
7a2554d9a3
@@ -1,6 +1,6 @@
|
||||
class Integer
|
||||
# Check whether the integer is evenly divisible by the argument.
|
||||
def multiple_of?(number)
|
||||
self % number == 0
|
||||
number != 0 ? self % number == 0 : zero?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,11 @@ class IntegerExtTest < Test::Unit::TestCase
|
||||
def test_multiple_of
|
||||
[ -7, 0, 7, 14 ].each { |i| assert i.multiple_of?(7) }
|
||||
[ -7, 7, 14 ].each { |i| assert ! i.multiple_of?(6) }
|
||||
|
||||
# test the 0 edge case
|
||||
assert 0.multiple_of?(0)
|
||||
assert !5.multiple_of?(0)
|
||||
|
||||
# test with a prime
|
||||
assert !22953686867719691230002707821868552601124472329079.multiple_of?(2)
|
||||
assert !22953686867719691230002707821868552601124472329079.multiple_of?(3)
|
||||
|
||||
Reference in New Issue
Block a user