1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Specify which core classes are convertible (#5790)

This commit is contained in:
Burdette Lamar 2022-04-11 13:49:38 -05:00 committed by GitHub
parent 5f1f8c244d
commit 7d709ceb12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2022-04-12 03:50:00 +09:00
Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>

View file

@ -2,6 +2,7 @@
Some Ruby methods accept one or more objects Some Ruby methods accept one or more objects
that can be either: that can be either:
* <i>Of a given class</i>, and so accepted as is. * <i>Of a given class</i>, and so accepted as is.
* <i>Implicitly convertible to that class</i>, in which case * <i>Implicitly convertible to that class</i>, in which case
the called method converts the object. the called method converts the object.
@ -17,10 +18,15 @@ a specific conversion method:
=== Array-Convertible Objects === Array-Convertible Objects
An <i>Array-convertible object</i> is an object that: An <i>Array-convertible object</i> is an object that:
* Has instance method +to_ary+. * Has instance method +to_ary+.
* The method accepts no arguments. * The method accepts no arguments.
* The method returns an object +obj+ for which <tt>obj.kind_of?(Array)</tt> returns +true+. * 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>, The examples in this section use method <tt>Array#replace</tt>,
which accepts an Array-convertible argument. 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 === Hash-Convertible Objects
A <i>Hash-convertible object</i> is an object that: A <i>Hash-convertible object</i> is an object that:
* Has instance method +to_hash+. * Has instance method +to_hash+.
* The method accepts no arguments. * The method accepts no arguments.
* The method returns an object +obj+ for which <tt>obj.kind_of?(Hash)</tt> returns +true+. * 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>, The examples in this section use method <tt>Hash#merge</tt>,
which accepts a Hash-convertible argument. 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 === Integer-Convertible Objects
An <i>Integer-convertible object</i> is an object that: An <i>Integer-convertible object</i> is an object that:
* Has instance method +to_int+. * Has instance method +to_int+.
* The method accepts no arguments. * The method accepts no arguments.
* The method returns an object +obj+ for which <tt>obj.kind_of?(Integer)</tt> returns +true+. * 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>, The examples in this section use method <tt>Array.new</tt>,
which accepts an Integer-convertible argument. 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 accepts no arguments.
* The method returns an object +obj+ for which <tt>obj.kind_of?(String)</tt> returns +true+. * 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>, The examples in this section use method <tt>String::new</tt>,
which accepts a String-convertible argument. which accepts a String-convertible argument.