Fix Integer#ceildiv to respect #coerce (#7118)

Fixes [Bug #19343]
This commit is contained in:
Kouhei Yanagita 2023-01-22 18:53:02 +09:00 committed by GitHub
parent cad09f7098
commit 20a85ab611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
Notes: git 2023-01-22 09:53:28 +00:00
Merged-By: mrkn <mrkn@ruby-lang.org>
2 changed files with 5 additions and 1 deletions

View File

@ -278,7 +278,7 @@ class Integer
#
# 3.ceildiv(1.2) # => 3
def ceildiv(other)
-div(-other)
-div(0 - other)
end
#

View File

@ -725,5 +725,9 @@ class TestInteger < Test::Unit::TestCase
assert_equal(10, (10**100-11).ceildiv(10**99-1))
assert_equal(11, (10**100-9).ceildiv(10**99-1))
o = Object.new
def o.coerce(other); [other, 10]; end
assert_equal(124, 1234.ceildiv(o))
end
end