зеркало из https://github.com/github/ruby.git
Specify which core classes are convertible (#5790)
This commit is contained in:
Родитель
5f1f8c244d
Коммит
7d709ceb12
|
@ -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.
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче