summaryrefslogtreecommitdiffstats
path: root/time.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-04 07:37:10 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-04 07:37:10 +0000
commitcfe19e4a9c8be5de4fed8f6f3491fedaa1d5ef42 (patch)
tree55d50b0856f96e2a2db8d68d8555403078531a61 /time.c
parentbaca009e446ed15c0bd0c86a66183ce749c81d93 (diff)
downloadruby-cfe19e4a9c8be5de4fed8f6f3491fedaa1d5ef42.tar.gz
ruby-cfe19e4a9c8be5de4fed8f6f3491fedaa1d5ef42.tar.xz
ruby-cfe19e4a9c8be5de4fed8f6f3491fedaa1d5ef42.zip
* time.c (num_exact): should not accept strings as operands, even
though they respond to #to_r. ideally, strict rational conversion should be done by a method like #to_rational, not #to_r. [ruby-core:23729] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/time.c b/time.c
index 8d6438809..0a73f8efa 100644
--- a/time.c
+++ b/time.c
@@ -214,19 +214,22 @@ num_exact(VALUE v)
v = rb_convert_type(v, T_RATIONAL, "Rational", "to_r");
break;
+ case T_STRING:
case T_NIL:
goto typeerror;
default: {
VALUE tmp;
- if (!NIL_P(tmp = rb_check_convert_type(v, T_RATIONAL, "Rational", "to_r")))
+ if (!NIL_P(tmp = rb_check_convert_type(v, T_RATIONAL, "Rational", "to_r"))) {
+ if (rb_respond_to(v, rb_intern("to_str"))) goto typeerror;
v = tmp;
+ }
else if (!NIL_P(tmp = rb_check_to_integer(v, "to_int")))
v = tmp;
else {
typeerror:
rb_raise(rb_eTypeError, "can't convert %s into an exact number",
- rb_obj_classname(v));
+ NIL_P(v) ? "nil" : rb_obj_classname(v));
}
break;
}