Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
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 eql?:
[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:
[0, 1, 2].intersection([2, 1, 0]) # => [0, 1, 2]
Returns a copy of self if no arguments given.
Related: Array#&.
 
               static VALUE
rb_ary_intersection_multi(int argc, VALUE *argv, VALUE ary)
{
    VALUE result = rb_ary_dup(ary);
    int i;

    for (i = 0; i < argc; i++) {
        result = rb_ary_and(result, argv[i]);
    }

    return result;
}
            

Was this page useful?