From fe2a6f65b1108fc71d269daaf1c7f4d89ebec0cb Mon Sep 17 00:00:00 2001 From: mrkn Date: Tue, 27 Feb 2018 16:45:09 +0000 Subject: 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 --- rational.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'rational.c') 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); -- cgit v1.2.3