aboutsummaryrefslogtreecommitdiffstats
path: root/rational.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-17 01:24:22 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-17 01:24:22 +0000
commitb30d203fed8c29fd05d010631ca8e4750ce34849 (patch)
treed1147089a3be6f5b09b4a5bb4e53ac5f5ab3ae83 /rational.c
parent783fb0881f91d59dca1430657628c4d50bd1a2be (diff)
downloadruby-b30d203fed8c29fd05d010631ca8e4750ce34849.tar.gz
* rational.c (nurat_coerce): Rational#coerce should converts itself
into Complex if the argument is a Complex with non-zero imaginary part. [Bug #5020] [ruby-dev:44088] * test/ruby/test_rational.rb (test_coerce): test for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/rational.c b/rational.c
index 8dac978ca7..40b480df6e 100644
--- a/rational.c
+++ b/rational.c
@@ -1108,6 +1108,8 @@ nurat_coerce(VALUE self, VALUE other)
if (k_exact_zero_p(RCOMPLEX(other)->imag))
return rb_assoc_new(f_rational_new_bang1
(CLASS_OF(self), RCOMPLEX(other)->real), self);
+ else
+ return rb_assoc_new(other, rb_Complex(self, INT2FIX(0)));
}
rb_raise(rb_eTypeError, "%s can't be coerced into %s",