From 454b4da7635b6322e85fd38735d9a04963644c4b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 8 Dec 2021 17:59:16 +0900 Subject: [DOC] Integer.try_convert [ci skip] --- numeric.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'numeric.rb') diff --git a/numeric.rb b/numeric.rb index 08b31ac307..d48a4ee336 100644 --- a/numeric.rb +++ b/numeric.rb @@ -229,6 +229,25 @@ class Integer end end +# call-seq: +# Integer.try_convert(object) -> object, integer, or nil +# +# If +object+ is an \Integer object, returns +object+. +# +# Otherwise if +object+ responds to :to_int, +# calls object.to_int and returns the result. +# +# Returns +nil+ if +object+ does not respond to :to_ary +# +# Raises an exception unless object.to_int returns an \Integer object. +# +def Integer.try_convert(num) +=begin + Primitive.attr! 'inline' + Primitive.cexpr! 'rb_check_integer_type(num)' +=end +end if false + class Float # # call-seq: -- cgit v1.2.1