summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2018-10-07 13:02:46 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-07-16 17:49:53 +0900
commit301d194ee3b49e6b078eccb999dd538e9bfa8c7c (patch)
tree8488af78fa5c0f0dab79905a577e365acef7ca01 /numeric.c
parenteee709595cecdbc35d7bca9e779c36523c4659c5 (diff)
downloadruby-301d194ee3b49e6b078eccb999dd538e9bfa8c7c.tar.gz
Add Integer.try_convert [Feature #15211]
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/numeric.c b/numeric.c
index c9dc24bcf1..345067c6a5 100644
--- a/numeric.c
+++ b/numeric.c
@@ -5247,6 +5247,12 @@ rb_int_s_isqrt(VALUE self, VALUE num)
}
}
+static VALUE
+int_s_try_convert(VALUE self, VALUE num)
+{
+ return rb_check_integer_type(num);
+}
+
/*
* Document-class: ZeroDivisionError
*
@@ -5473,6 +5479,7 @@ Init_Numeric(void)
rb_undef_alloc_func(rb_cInteger);
rb_undef_method(CLASS_OF(rb_cInteger), "new");
rb_define_singleton_method(rb_cInteger, "sqrt", rb_int_s_isqrt, 1);
+ rb_define_singleton_method(rb_cInteger, "try_convert", int_s_try_convert, 1);
rb_define_method(rb_cInteger, "to_s", int_to_s, -1);
rb_define_alias(rb_cInteger, "inspect", "to_s");