summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-18 13:41:44 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-18 13:41:44 +0000
commit67f93ddc216c56298aeb9981fc36649987438457 (patch)
treeceacba47fb0d461ee9846a40f194c2a87544bbb3 /complex.c
parent430eb945ceeec646f30ee79302d2f265b25bc1ee (diff)
* rational.c (nurat_s_convert): calls to_r when the given argument
is non-integer. * rational.c (nurat_s_convert): raises TypeError when the given argument is nil. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/complex.c b/complex.c
index 0e9a17b7a6..630f25b1eb 100644
--- a/complex.c
+++ b/complex.c
@@ -1248,6 +1248,9 @@ nucomp_s_convert(int argc, VALUE *argv, VALUE klass)
rb_scan_args(argc, argv, "11", &a1, &a2);
+ if (NIL_P(a1) || (argc == 2 && NIL_P(a2)))
+ rb_raise(rb_eTypeError, "can't convert nil into Complex");
+
backref = rb_backref_get();
rb_match_busy(backref);
@@ -1302,6 +1305,9 @@ nucomp_s_convert(int argc, VALUE *argv, VALUE klass)
if (argc == 1) {
if (k_numeric_p(a1) && !f_real_p(a1))
return a1;
+ /* expect raise exception for consistency */
+ if (!k_numeric_p(a1))
+ return rb_convert_type(a1, T_COMPLEX, "Complex", "to_c");
}
else {
if ((k_numeric_p(a1) && k_numeric_p(a2)) &&