[DOC] Tweaks for Array#intersection (#11745)

This commit is contained in:
Burdette Lamar 2024-10-02 10:11:29 -05:00 committed by GitHub
parent 75ab01f3b7
commit a7c04a317f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2024-10-02 15:11:47 +00:00
Merged-By: peterzhu2118 <peter@peterzhu.ca>

18
array.c
View File

@ -5624,23 +5624,23 @@ rb_ary_and(VALUE ary1, VALUE ary2)
/*
* call-seq:
* array.intersection(*other_arrays) -> new_array
* intersection(*other_arrays) -> new_array
*
* Returns a new +Array+ containing each element found both in +self+
* and in all of the given Arrays +other_arrays+;
* duplicates are omitted; items are compared using <tt>eql?</tt>
* (items must also implement +hash+ correctly):
* Returns a new array containing each element in +self+ that is +#eql?+
* to at least one element in each of the given +other_arrays+;
* duplicates are omitted:
*
* [0, 1, 2, 3].intersection([0, 1, 2], [0, 1, 3]) # => [0, 1]
* [0, 0, 1, 1, 2, 3].intersection([0, 1, 2], [0, 1, 3]) # => [0, 1]
*
* Preserves order from +self+:
* Each element must correctly implement method <tt>#hash</tt>.
*
* Order from +self+ is preserved:
*
* [0, 1, 2].intersection([2, 1, 0]) # => [0, 1, 2]
*
* Returns a copy of +self+ if no arguments given.
* Returns a copy of +self+ if no arguments are given.
*
* Related: Array#&.
* Related: see {Methods for Combining}[rdoc-ref:Array@Methods+for+Combining].
*/
static VALUE