diff --git a/numeric.c b/numeric.c index 74771cba6f..74ee5d136a 100644 --- a/numeric.c +++ b/numeric.c @@ -243,7 +243,10 @@ rb_num_get_rounding_option(VALUE opts) break; } invalid: - rb_raise(rb_eArgError, "invalid rounding mode: % "PRIsVALUE, rounding); + if (NIL_P(rounding)) + rb_raise(rb_eArgError, "invalid rounding mode: nil"); + else + rb_raise(rb_eArgError, "invalid rounding mode: % "PRIsVALUE, rounding); } noopt: return RUBY_NUM_ROUND_DEFAULT; diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index aed387029e..eccc86740a 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -723,6 +723,9 @@ class TestFloat < Test::Unit::TestCase end def test_round_half_invalid + assert_raise_with_message(ArgumentError, /nil/) { + 1.0.round(half: nil) + } assert_raise_with_message(ArgumentError, /xxx/) { 1.0.round(half: "\0xxx") }