Issue #5020 has been reported by Usaku NAKAMURA.

----------------------------------------
Bug #5020: Rational cannot coerce into Complex with imag.
http://redmine.ruby-lang.org/issues/5020

Author: Usaku NAKAMURA
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 1.9.3
ruby -v: ruby 1.9.4dev (2011-07-11 trunk 32518) [x64-mswin64_100]


??????????????????????????????????????????????????????Complex????????????Rational#coerce????????TypeError?????????????????

 Rational(1,2).coerce(Complex(1,1)) #=> TypeError

???????????????????????????????????????????????Rational????????????

 Rational(1,2).coerce(Complex(1,0)) #=> [(1/1), (1/2)]

???????????????????????????????????Complex????????????????????????coerce????????????????????????Complex????????????

 Complex(1,0).coerce(Rational(1,2)) #=> [((1/2)+0i), (1+0i)]
 Complex(1,1).coerce(Rational(1,2)) #=> [((1/2)+0i), (1+1i)]

Rational#coerce(aComplex)???aComplex??????????????????Rational????????????????????????????????????????????????????????????????TypeError????????????????????????????
???????????????????????

Index: rational.c
===================================================================
--- rational.c	(revision 32520)
+++ rational.c	(working copy)
@@ -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",



-- 
http://redmine.ruby-lang.org