Skip to content

Commit

Permalink
Fix Integer#ceildiv to respect #coerce (#7118)
Browse files Browse the repository at this point in the history
Fixes [Bug #19343]
  • Loading branch information
kyanagi committed Jan 22, 2023
1 parent cad09f7 commit 20a85ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numeric.rb
Expand Up @@ -278,7 +278,7 @@ def zero?
#
# 3.ceildiv(1.2) # => 3
def ceildiv(other)
-div(-other)
-div(0 - other)
end

#
Expand Down
4 changes: 4 additions & 0 deletions test/ruby/test_integer.rb
Expand Up @@ -725,5 +725,9 @@ def test_ceildiv

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

0 comments on commit 20a85ab

Please sign in to comment.