From 7d709ceb12259b2b863a4a1f484987840d174514 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Mon, 11 Apr 2022 13:49:38 -0500 Subject: [PATCH] Specify which core classes are convertible (#5790) --- doc/implicit_conversion.rdoc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/doc/implicit_conversion.rdoc b/doc/implicit_conversion.rdoc index 0c2a1d4971..ba15fa4bf4 100644 --- a/doc/implicit_conversion.rdoc +++ b/doc/implicit_conversion.rdoc @@ -2,6 +2,7 @@ Some Ruby methods accept one or more objects that can be either: + * Of a given class, and so accepted as is. * Implicitly convertible to that class, in which case the called method converts the object. @@ -17,10 +18,15 @@ a specific conversion method: === Array-Convertible Objects An Array-convertible object is an object that: + * Has instance method +to_ary+. * The method accepts no arguments. * The method returns an object +obj+ for which obj.kind_of?(Array) returns +true+. +The Ruby core class that satisfies these requirements is: + +* Array + The examples in this section use method Array#replace, which accepts an Array-convertible argument. @@ -66,10 +72,15 @@ This class is not Array-convertible (method +to_ary+ returns non-Array): === Hash-Convertible Objects A Hash-convertible object is an object that: + * Has instance method +to_hash+. * The method accepts no arguments. * The method returns an object +obj+ for which obj.kind_of?(Hash) returns +true+. +The Ruby core class that satisfies these requirements is: + +* Hash + The examples in this section use method Hash#merge, which accepts a Hash-convertible argument. @@ -115,10 +126,18 @@ This class is not Hash-convertible (method +to_hash+ returns non-Hash): === Integer-Convertible Objects An Integer-convertible object is an object that: + * Has instance method +to_int+. * The method accepts no arguments. * The method returns an object +obj+ for which obj.kind_of?(Integer) returns +true+. +The Ruby core classes that satisfy these requirements are: + +* Integer +* Float +* Complex +* Rational + The examples in this section use method Array.new, which accepts an Integer-convertible argument. @@ -159,6 +178,10 @@ A String-convertible object is an object that: * The method accepts no arguments. * The method returns an object +obj+ for which obj.kind_of?(String) returns +true+. +The Ruby core class that satisfies these requirements is: + +* String + The examples in this section use method String::new, which accepts a String-convertible argument.