diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-11-13 05:39:35 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-11-13 05:39:35 +0000 |
| commit | ee163b4ebf8f30f133e33a45cf8c879a3b5a09e9 (patch) | |
| tree | 84e15b31de72e95a48dc2f0063477bba838b8060 /object.c | |
| parent | b5f3220dfab86e2ac94e0120b8a544ee08a44319 (diff) | |
| download | ruby-ee163b4ebf8f30f133e33a45cf8c879a3b5a09e9.tar.gz ruby-ee163b4ebf8f30f133e33a45cf8c879a3b5a09e9.tar.xz ruby-ee163b4ebf8f30f133e33a45cf8c879a3b5a09e9.zip | |
matz
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@1037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
| -rw-r--r-- | object.c | 41 |
1 files changed, 28 insertions, 13 deletions
@@ -871,12 +871,37 @@ rb_convert_type(val, type, tname, method) return val; } -VALUE -rb_Integer(val) +static VALUE +rb_to_integer(val, method) VALUE val; + char *method; { struct arg_to arg1, arg2; + + arg1.val = arg2.val = val; + arg1.s = method; + arg2.s = "Integer"; + val = rb_rescue2(to_type, (VALUE)&arg1, fail_to_type, (VALUE)&arg2, + rb_eStandardError, rb_eNameError, 0); + if (!rb_obj_is_kind_of(val, rb_cInteger)) { + rb_raise(rb_eTypeError, "%s#%s_i should return Integer", + method, rb_class2name(CLASS_OF(arg1.val))); + } + return val; +} + +VALUE +rb_to_int(val) + VALUE val; +{ + return rb_to_integer(val, "to_int"); +} + +VALUE +rb_Integer(val) + VALUE val; +{ switch (TYPE(val)) { case T_FLOAT: if (RFLOAT(val)->value <= (double)FIXNUM_MAX @@ -897,17 +922,7 @@ rb_Integer(val) default: break; } - - arg1.val = arg2.val = val; - arg1.s = "to_i"; - arg2.s = "Integer"; - val = rb_rescue2(to_type, (VALUE)&arg1, fail_to_type, (VALUE)&arg2, - rb_eStandardError, rb_eNameError, 0); - if (!rb_obj_is_kind_of(val, rb_cInteger)) { - rb_raise(rb_eTypeError, "%s#to_i should return Integer", - rb_class2name(CLASS_OF(arg1.val))); - } - return val; + return rb_to_integer(val, "to_i"); } static VALUE |
