From 2a1b0ff2326ae53c299206f983413fa00a2c7ec5 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 13 Nov 2000 05:39:35 +0000 Subject: matz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 0e2285ee0a..9b5d50a457 100644 --- a/object.c +++ b/object.c @@ -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 -- cgit v1.2.3