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 | 2a1b0ff2326ae53c299206f983413fa00a2c7ec5 (patch) | |
tree | 84e15b31de72e95a48dc2f0063477bba838b8060 /object.c | |
parent | 1db8e80b29f41a3e413626bca4b95ff6a4cfe522 (diff) |
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/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 |