From b8f7fc361d2cf2266e39e97c57bba6edd6c6edaf Mon Sep 17 00:00:00 2001 From: Matheus Richard 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(+) (limited to 'numeric.rb') diff --git a/numeric.rb b/numeric.rb index eea1ac96cd..9f2200d2a8 100644 --- a/numeric.rb +++ b/numeric.rb @@ -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 :to_int, # calls object.to_int and returns the result. +# Integer.try_convert(1.25) # => 1 # # Returns +nil+ if +object+ does not respond to :to_int +# Integer.try_convert([]) # => nil # # Raises an exception unless object.to_int returns an \Integer object. # -- cgit v1.2.1