instance method
Array#|
[T] (::Array[T] other_ary) -> ::Array[Elem | T]
self | other_array → new_array
array.c
View on GitHub ↗
static VALUE
rb_ary_or(VALUE ary1, VALUE ary2)
{
VALUE hash;
ary2 = to_ary(ary2);
if (RARRAY_LEN(ary1) + RARRAY_LEN(ary2) <= SMALL_ARRAY_LEN) {
VALUE ary3 = rb_ary_new();
rb_ary_union(ary3, ary1);
rb_ary_union(ary3, ary2);
return ary3;
}
hash = ary_make_hash(ary1);
rb_ary_union_hash(hash, ary2);
return rb_hash_values(hash);
}
Returns the union of self and other_array; duplicates are removed; order is preserved; items are compared using eql?:
Example
[0, 1] | [2, 3] # => [0, 1, 2, 3] [0, 1, 1] | [2, 2, 3] # => [0, 1, 2, 3] [0, 1, 2] | [3, 2, 1, 0] # => [0, 1, 2, 3]
Related: see Methods for Combining.