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

Enhanced RDoc for Array (#3350)

* Enhanced RDoc for Array

Methods:

    ==
    eql?
    hash
    include?
    <=>
This commit is contained in:
Burdette Lamar 2020-07-22 19:06:49 -05:00 committed by GitHub
parent 37e6c83609
commit 5d04ac6ea2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2020-07-23 09:07:15 +09:00
Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>

110
array.c
View file

@ -5637,16 +5637,23 @@ recursive_equal(VALUE ary1, VALUE ary2, int recur)
/* /*
* call-seq: * call-seq:
* ary == other_ary -> bool * array == other_array -> true or false
* *
* Equality --- Two arrays are equal if they contain the same number of * Returns +true+ if both <tt>array.size == other_array.size</tt>
* elements and if each element is equal to (according to Object#==) the * and for each index +i+ in +array+, <tt>array[i] == other_array[i]</tt>:
* corresponding element in +other_ary+. * a0 = [:foo, 'bar', 2]
* a1 = [:foo, 'bar', 2.0]
* a1 == a0 # => true
* [] == [] # => true
* *
* [ "a", "c" ] == [ "a", "c", 7 ] #=> false * Otherwise, returns +false+:
* [ "a", "c", 7 ] == [ "a", "c", 7 ] #=> true * a0 == [:foo, 'bar'] # => false # Different sizes
* [ "a", "c", 7 ] == [ "a", "d", "f" ] #=> false * a0 == [:foo, 'bar', 3] # => false # Different elements
* *
* This method is different from method Array#eql?,
* which compares elements using <tt>Object#eql?</tt>:
* a1[2].eql?(a0[2]) # false
* a1.eql?(a0) # => false
*/ */
static VALUE static VALUE
@ -5679,10 +5686,26 @@ recursive_eql(VALUE ary1, VALUE ary2, int recur)
/* /*
* call-seq: * call-seq:
* ary.eql?(other) -> true or false * array.eql? other_array -> true or false
* *
* Returns +true+ if +self+ and +other+ are the same object, * Returns +true+ if +self+ and +other_array+ are the same size,
* or are both arrays with the same content (according to Object#eql?). * and if, for each index +i+ in +self+, <tt>self[i].eql? other_array[i]</tt>:
* a0 = [:foo, 'bar', 2]
* a1 = [:foo, 'bar', 2]
* a1.eql?(a0) # => true
* [].eql? [] # => true
*
* Otherwise, returns +false+:
* a0 = [:foo, 'bar', 2]
* a1 = [:foo, 'bar', 2.0]
* a1.eql?(a0) # => false # Because 2.eql?(2.0) is false
* a1.eql? [0, 1] # => false
*
* This method is different from method <tt>Array#==</tt>,
* which compares using method <tt>Object#==</tt>:
* a0 = [:foo, 'bar', 2]
* a1 = [:foo, 'bar', 2.0]
* a1 == a0 # => true
*/ */
static VALUE static VALUE
@ -5697,14 +5720,14 @@ rb_ary_eql(VALUE ary1, VALUE ary2)
/* /*
* call-seq: * call-seq:
* ary.hash -> integer * array.hash -> integer
* *
* Compute a hash-code for this array. * Returns the integer hash value for +self+:
* [].hash.class # => Integer
* *
* Two arrays with the same content will have the same hash code (and will * Two arrays with the same content will have the same hash code (and will compare using eql?):
* compare using #eql?). * [0, 1, 2].hash == [0, 1, 2].hash # => true
* * [0, 1, 2].hash == [0, 1, 3].hash # => false
* See also Object#hash.
*/ */
static VALUE static VALUE
@ -5726,14 +5749,12 @@ rb_ary_hash(VALUE ary)
/* /*
* call-seq: * call-seq:
* ary.include?(object) -> true or false * array.include?(obj) -> true or false
* *
* Returns +true+ if the given +object+ is present in +self+ (that is, if any * Returns +true+ if for some index +i+ in +self+, <tt>obj == self[i]</tt>;
* element <code>==</code> +object+), otherwise returns +false+. * otherwise +false+:
* * [0, 1, 2].include?(2) # => true
* a = [ "a", "b", "c" ] * [0, 1, 2].include?(3) # => false
* a.include?("b") #=> true
* a.include?("z") #=> false
*/ */
VALUE VALUE
@ -5788,32 +5809,37 @@ recursive_cmp(VALUE ary1, VALUE ary2, int recur)
/* /*
* call-seq: * call-seq:
* ary <=> other_ary -> -1, 0, +1 or nil * array <=> other_array -1, 0, or 1
* *
* Comparison --- Returns an integer (+-1+, +0+, or <code>+1</code>) if this * Returns -1, 0, or 1 as +self+ is less than, equal to, or greater than +other_array+.
* array is less than, equal to, or greater than +other_ary+. * For each index +i+ in +self+, evaluates <tt>result = self[i] <=> other_array[i]</tt>.
* *
* Each object in each array is compared (using the <=> operator). * ---
* *
* Arrays are compared in an "element-wise" manner; the first element of +ary+ * Returns -1 if any result is -1:
* is compared with the first one of +other_ary+ using the <=> operator, then * [0, 1, 2] <=> [0, 1, 3] # => -1
* each of the second elements, etc... * Returns 1 if any result is 1:
* As soon as the result of any such comparison is non zero (i.e. the two * [0, 1, 2] <=> [0, 1, 1] # => 1
* corresponding elements are not equal), that result is returned for the
* whole array comparison.
* *
* If all the elements are equal, then the result is based on a comparison of * ---
* the array lengths. Thus, two arrays are "equal" according to Array#<=> if,
* and only if, they have the same length and the value of each element is
* equal to the value of the corresponding element in the other array.
* *
* +nil+ is returned if the +other_ary+ is not an array or if the comparison * When all results are zero:
* of two elements returned +nil+. * - Returns -1 if +array+ is smaller than +other_array+:
* [0, 1, 2] <=> [0, 1, 2, 3] # => -1
* - Returns 1 if +array+ is larger than +other_array+:
* [0, 1, 2] <=> [0, 1] # => 1
* - Returns 0 if +array+ and +other_array+ are the same size:
* [0, 1, 2] <=> [0, 1, 2] # => 0
* *
* [ "a", "a", "c" ] <=> [ "a", "b", "c" ] #=> -1 * ---
* [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1
* [ 1, 2 ] <=> [ 1, :two ] #=> nil
* *
* Argument +other_array+ may be an
* {Array-convertible object}[doc/implicit_conversion_rdoc.html#label-Array-Convertible+Objects]:
* require 'csv'
* [] <=> CSV::Row.new([], []) # => 0
*
* Returns +nil+ if +other_array+ is not an Array-convertible object:
* [] <=> 0 # => nil
*/ */
VALUE VALUE