From c5fc4da7a22fa4125afc8b70876b3f7d52404001 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 11 Dec 2011 01:37:50 +0000 Subject: [PATCH] * object.c (rb_check_to_int): new function to convert a VALUE to an Integer if possible, but returns nil instead of raising an exception otherwise. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ include/ruby/intern.h | 1 + object.c | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3e1de62240..262b030567 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Dec 11 10:37:47 2011 Nobuyoshi Nakada + + * object.c (rb_check_to_int): new function to convert a VALUE to + an Integer if possible, but returns nil instead of raising an + exception otherwise. + Sun Dec 11 10:34:39 2011 Nobuyoshi Nakada * process.c (rb_exit_status_code): extract from rb_f_exit_bang and diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 675694179b..fbc9c49cfb 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -553,6 +553,7 @@ VALUE rb_check_convert_type(VALUE,int,const char*,const char*); VALUE rb_check_to_integer(VALUE, const char *); VALUE rb_check_to_float(VALUE); VALUE rb_to_int(VALUE); +VALUE rb_check_to_int(VALUE); VALUE rb_Integer(VALUE); VALUE rb_to_float(VALUE); VALUE rb_Float(VALUE); diff --git a/object.c b/object.c index 4881cfd324..82fab4a812 100644 --- a/object.c +++ b/object.c @@ -2187,6 +2187,12 @@ rb_to_int(VALUE val) return rb_to_integer(val, "to_int"); } +VALUE +rb_check_to_int(VALUE val) +{ + return rb_check_to_integer(val, "to_int"); +} + static VALUE rb_convert_to_integer(VALUE val, int base) {