diff options
author | Kouhei Yanagita <yanagi@shakenbu.org> | 2023-01-22 18:53:02 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-22 18:53:02 +0900 |
commit | 20a85ab6119964d1ff129f9c6676fa2a7b2a2be4 (patch) | |
tree | a484952f92a62b17e1666639cbf1680d0afe4e7f | |
parent | cad09f7098d11ae32e5c10fa3726399621b4f8bd (diff) |
Fix Integer#ceildiv to respect #coerce (#7118)
Fixes [Bug #19343]
Notes
Notes:
Merged-By: mrkn <mrkn@ruby-lang.org>
-rw-r--r-- | numeric.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_integer.rb | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/numeric.rb b/numeric.rb index f026679210..0a1f14865f 100644 --- a/numeric.rb +++ b/numeric.rb @@ -278,7 +278,7 @@ class Integer # # 3.ceildiv(1.2) # => 3 def ceildiv(other) - -div(-other) + -div(0 - other) end # diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index dd177090ab..a3e64ddb38 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -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 |