ruby-changes:70209
From: Matheus <ko1@a...>
Date: Wed, 15 Dec 2021 02:12:53 +0900 (JST)
Subject: [ruby-changes:70209] b8f7fc361d (master): Add examples for Integer.try_convert [ci skip]
https://git.ruby-lang.org/ruby.git/commit/?id=b8f7fc361d From b8f7fc361d2cf2266e39e97c57bba6edd6c6edaf Mon Sep 17 00:00:00 2001 From: Matheus Richard <matheusrichardt@g...> Date: Tue, 14 Dec 2021 14:12:37 -0300 Subject: Add examples for Integer.try_convert [ci skip] --- numeric.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numeric.rb b/numeric.rb index eea1ac96cd8..9f2200d2a87 100644 --- a/numeric.rb +++ b/numeric.rb @@ -233,11 +233,14 @@ end https://github.com/ruby/ruby/blob/trunk/numeric.rb#L233 # 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. # -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/