diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-27 16:45:09 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-27 16:45:09 +0000 |
commit | 5c113bf25cfa5c4aee9f9f7b27634b63f91b5e3d (patch) | |
tree | 822d5d361d37977ece6a0dc0d85f04c549151d18 /rational.c | |
parent | 9a4c30e3e37f95b35f0f0ee79022258ee1f3ed24 (diff) | |
download | ruby-5c113bf25cfa5c4aee9f9f7b27634b63f91b5e3d.tar.gz |
Support two `to_r`-responding args in Rational()
* rational.c (nurat_s_convert): call `to_r` to convert non-Numeric
objects also if argc == 2 in Rational().
* test/ruby/test_rational.rb: add tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r-- | rational.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/rational.c b/rational.c index c350ad32b7..b648b19438 100644 --- a/rational.c +++ b/rational.c @@ -2548,6 +2548,12 @@ nurat_s_convert(int argc, VALUE *argv, VALUE klass) return rb_convert_type_with_id(a1, T_RATIONAL, "Rational", idTo_r); } else { + if (!k_numeric_p(a1)) { + a1 = rb_check_convert_type_with_id(a1, T_RATIONAL, "Rational", idTo_r); + } + if (!k_numeric_p(a2)) { + a2 = rb_check_convert_type_with_id(a2, T_RATIONAL, "Rational", idTo_r); + } if ((k_numeric_p(a1) && k_numeric_p(a2)) && (!f_integer_p(a1) || !f_integer_p(a2))) return f_div(a1, a2); |