1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[Bug #18998] Honor #to_str next to #to_int in Kernel#Integer

This commit is contained in:
Nobuyoshi Nakada 2022-10-20 14:07:35 +09:00
parent 4f1e0bfacd
commit 7563604fb8
Notes: git 2022-10-20 06:35:52 +00:00
2 changed files with 10 additions and 0 deletions

View file

@ -3138,6 +3138,9 @@ rb_convert_to_integer(VALUE val, int base, int raise_exception)
tmp = rb_protect(rb_check_to_int, val, NULL);
if (RB_INTEGER_TYPE_P(tmp)) return tmp;
rb_set_errinfo(Qnil);
if (!NIL_P(tmp = rb_check_string_type(val))) {
return rb_str_convert_to_inum(tmp, base, TRUE, raise_exception);
}
if (!raise_exception) {
VALUE result = rb_protect(rb_check_to_i, val, NULL);

View file

@ -247,6 +247,13 @@ class TestInteger < Test::Unit::TestCase
end;
end
def test_Integer_when_to_str
def (obj = Object.new).to_str
"0x10"
end
assert_equal(16, Integer(obj))
end
def test_int_p
assert_not_predicate(1.0, :integer?)
assert_predicate(1, :integer?)