diff options
author | Nobuyoshi Nakada <[email protected]> | 2021-12-08 17:59:16 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-12-08 17:59:16 +0900 |
commit | 454b4da7635b6322e85fd38735d9a04963644c4b (patch) | |
tree | a00f77f16d595a613cc7784abbd67459f5d63b35 /numeric.rb | |
parent | af6e0883570e8c61cef6234040d8689d88db7300 (diff) |
[DOC] Integer.try_convert [ci skip]
Diffstat (limited to 'numeric.rb')
-rw-r--r-- | numeric.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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 <tt>:to_int</tt>, +# calls <tt>object.to_int</tt> and returns the result. +# +# Returns +nil+ if +object+ does not respond to <tt>:to_ary</tt> +# +# Raises an exception unless <tt>object.to_int</tt> 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: |