diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-29 06:09:40 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-29 06:09:40 +0000 |
commit | 83cb605d69f20be5fe842a913e51d017f61cdc44 (patch) | |
tree | b227250a931f8465854064c4860265d76a1974c9 /object.c | |
parent | 6e221605373ff89fd52d08d5df86cfb0bd805de7 (diff) | |
download | ruby-83cb605d69f20be5fe842a913e51d017f61cdc44.tar.gz |
* object.c (convert_type): [ruby-core:03845]
* eval.c (rb_funcall_rescue): new function.
* object.c (rb_Array): avoid using rb_respond_to().
* object.c (rb_Integer): ditto.
* eval.c (get_backtrace): no conversion for nil.
* parse.y (reduce_nodes): empty body should return nil.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 29 |
1 files changed, 12 insertions, 17 deletions
@@ -2056,10 +2056,9 @@ convert_type(val, tname, method, raise) const char *tname, *method; int raise; { - ID m; + VALUE result = rb_funcall_rescue(val, rb_intern(method), 0); - m = rb_intern(method); - if (!rb_respond_to(val, m)) { + if (result == Qundef) { if (raise) { rb_raise(rb_eTypeError, "cannot convert %s into %s", NIL_P(val) ? "nil" : @@ -2069,10 +2068,11 @@ convert_type(val, tname, method, raise) tname); } else { + ruby_errinfo = Qnil; return Qnil; } } - return rb_funcall(val, m, 0); + return result; } VALUE @@ -2139,6 +2139,8 @@ VALUE rb_Integer(val) VALUE val; { + VALUE tmp; + switch (TYPE(val)) { case T_FLOAT: if (RFLOAT(val)->value <= (double)FIXNUM_MAX @@ -2157,10 +2159,11 @@ rb_Integer(val) default: break; } - if (rb_respond_to(val, rb_intern("to_int"))) { - return rb_to_integer(val, "to_int"); + tmp = convert_type(val, "Integer", "to_int", Qfalse); + if (NIL_P(tmp)) { + return rb_to_integer(val, "to_i"); } - return rb_to_integer(val, "to_i"); + return tmp; } /* @@ -2401,18 +2404,10 @@ rb_Array(val) VALUE val; { VALUE tmp = rb_check_array_type(val); - ID to_a; if (NIL_P(tmp)) { - to_a = rb_intern("to_a"); - if (rb_respond_to(val, to_a)) { - val = rb_funcall(val, to_a, 0); - if (TYPE(val) != T_ARRAY) { - rb_raise(rb_eTypeError, "`to_a' did not return Array"); - } - return val; - } - else { + tmp = rb_check_convert_type(val, T_ARRAY, "Array", "to_a"); + if (NIL_P(tmp)) { return rb_ary_new3(1, val); } } |