numeric.c: allow nil as rounding mode option

* numeric.c (rb_num_get_rounding_option): allow nil same as the
  default behavior, per [ruby-core:77961].  [Bug #12548]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-12-21 01:29:57 +00:00
parent 0adce99357
commit 114d1751dc
2 changed files with 5 additions and 2 deletions

View File

@ -209,6 +209,9 @@ rb_num_get_rounding_option(VALUE opts)
if (SYMBOL_P(rounding)) {
str = rb_sym2str(rounding);
}
else if (NIL_P(rounding)) {
goto noopt;
}
else if (!RB_TYPE_P(str = rounding, T_STRING)) {
str = rb_check_string_type(rounding);
if (NIL_P(str)) goto invalid;

View File

@ -723,8 +723,8 @@ 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, /Object/) {
1.0.round(half: Object)
}
assert_raise_with_message(ArgumentError, /xxx/) {
1.0.round(half: "\0xxx")