mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add examples for Integer.try_convert [ci skip]
This commit is contained in:
parent
b32b755ea2
commit
b8f7fc361d
Notes:
git
2021-12-15 02:12:59 +09:00
Merged: https://github.com/ruby/ruby/pull/5268 Merged-By: nobu <nobu@ruby-lang.org>
1 changed files with 3 additions and 0 deletions
|
@ -233,11 +233,14 @@ end
|
|||
# Integer.try_convert(object) -> object, integer, or nil
|
||||
#
|
||||
# If +object+ is an \Integer object, returns +object+.
|
||||
# Integer.try_convert(1) # => 1
|
||||
#
|
||||
# Otherwise if +object+ responds to <tt>:to_int</tt>,
|
||||
# calls <tt>object.to_int</tt> and returns the result.
|
||||
# Integer.try_convert(1.25) # => 1
|
||||
#
|
||||
# Returns +nil+ if +object+ does not respond to <tt>:to_int</tt>
|
||||
# Integer.try_convert([]) # => nil
|
||||
#
|
||||
# Raises an exception unless <tt>object.to_int</tt> returns an \Integer object.
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue