diff options
author | Burdette Lamar <[email protected]> | 2022-04-11 13:49:38 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2022-04-11 13:49:38 -0500 |
commit | 7d709ceb12259b2b863a4a1f484987840d174514 (patch) | |
tree | 907c992e77be9362628b5d128ec913c895b57dbf /doc/implicit_conversion.rdoc | |
parent | 5f1f8c244da69a69ff62475be4c022f2c7e850d4 (diff) |
Specify which core classes are convertible (#5790)
Notes
Notes:
Merged-By: BurdetteLamar <[email protected]>
Diffstat (limited to 'doc/implicit_conversion.rdoc')
-rw-r--r-- | doc/implicit_conversion.rdoc | 23 |
1 files changed, 23 insertions, 0 deletions
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: + * <i>Of a given class</i>, and so accepted as is. * <i>Implicitly convertible to that class</i>, in which case the called method converts the object. @@ -17,10 +18,15 @@ a specific conversion method: === Array-Convertible Objects An <i>Array-convertible object</i> is an object that: + * Has instance method +to_ary+. * The method accepts no arguments. * The method returns an object +obj+ for which <tt>obj.kind_of?(Array)</tt> returns +true+. +The Ruby core class that satisfies these requirements is: + +* Array + The examples in this section use method <tt>Array#replace</tt>, 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 <i>Hash-convertible object</i> is an object that: + * Has instance method +to_hash+. * The method accepts no arguments. * The method returns an object +obj+ for which <tt>obj.kind_of?(Hash)</tt> returns +true+. +The Ruby core class that satisfies these requirements is: + +* Hash + The examples in this section use method <tt>Hash#merge</tt>, 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 <i>Integer-convertible object</i> is an object that: + * Has instance method +to_int+. * The method accepts no arguments. * The method returns an object +obj+ for which <tt>obj.kind_of?(Integer)</tt> returns +true+. +The Ruby core classes that satisfy these requirements are: + +* Integer +* Float +* Complex +* Rational + The examples in this section use method <tt>Array.new</tt>, which accepts an Integer-convertible argument. @@ -159,6 +178,10 @@ A <i>String-convertible object</i> is an object that: * The method accepts no arguments. * The method returns an object +obj+ for which <tt>obj.kind_of?(String)</tt> returns +true+. +The Ruby core class that satisfies these requirements is: + +* String + The examples in this section use method <tt>String::new</tt>, which accepts a String-convertible argument. |