summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-06 13:31:22 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-06 13:31:22 +0000
commit7708560bb1c4686668268a2bca05da481b7c3132 (patch)
tree1321108064b7f1115498e64cb71c19c97bf09e40
parentb1411888d1c85835e92455fdd2af345d0be1cb0a (diff)
* numeric.c (num_quo): Use to_r method to convert the receiver to
rational. [ruby-core:41575] [Bug #5736] * test/ruby/test_numeric.rb: add a test for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--numeric.c6
-rw-r--r--test/ruby/test_numeric.rb15
3 files changed, 25 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index ac38b6a8000..45dc6fdfd81 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Jun 6 22:24:00 2013 Kenta Murata <mrkn@mrkn.jp>
+
+ * numeric.c (num_quo): Use to_r method to convert the receiver to
+ rational. [ruby-core:41575] [Bug #5736]
+
+ * test/ruby/test_numeric.rb: add a test for the above change.
+
Thu Jun 6 20:40:17 2013 Tanaka Akira <akr@fsij.org>
* configure.in: Invoke RUBY_REPLACE_TYPE for size_t.
diff --git a/numeric.c b/numeric.c
index e8d2f9df25f..4085062e1ec 100644
--- a/numeric.c
+++ b/numeric.c
@@ -101,7 +101,7 @@ static VALUE fix_uminus(VALUE num);
static VALUE fix_mul(VALUE x, VALUE y);
static VALUE int_pow(long x, unsigned long y);
-static ID id_coerce, id_to_i, id_eq, id_div;
+static ID id_coerce, id_to_i, id_to_r, id_eq, id_div;
VALUE rb_cNumeric;
VALUE rb_cFloat;
@@ -398,7 +398,8 @@ num_quo(VALUE x, VALUE y)
return num_fdiv(x, y);
}
- return rb_funcall(rb_rational_raw1(x), '/', 1, y);
+ x = rb_convert_type(x, T_RATIONAL, "Rational", "to_r");
+ return rb_funcall(x, '/', 1, y);
}
@@ -3774,6 +3775,7 @@ Init_Numeric(void)
#endif
id_coerce = rb_intern("coerce");
id_to_i = rb_intern("to_i");
+ id_to_r = rb_intern("to_r");
id_eq = rb_intern("==");
id_div = rb_intern("div");
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb
index 09b48ebc692..fccf17ed294 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -54,7 +54,20 @@ class TestNumeric < Test::Unit::TestCase
end
def test_quo
- assert_raise(ArgumentError) {DummyNumeric.new.quo(1)}
+ assert_raise(TypeError) {DummyNumeric.new.quo(1)}
+ end
+
+ def test_quo_ruby_core_41575
+ x = DummyNumeric.new
+ rat = 84.quo(1)
+ DummyNumeric.class_eval do
+ define_method(:to_r) { rat }
+ end
+ assert_equal(2.quo(1), x.quo(42), '[ruby-core:41575]')
+ ensure
+ DummyNumeric.class_eval do
+ remove_method :to_r
+ end
end
def test_divmod