Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Set#|
(::_Each[A]) -> self
self | enumerable → new_set
set.c
View on GitHub ↗
static VALUE
set_i_union(VALUE set, VALUE other)
{
set = rb_obj_dup(set);
set_merge_enum_into(set, other);
return set;
}
Returns a new set containing the union of self and the given enumerable; that is, containing the elements of both self and enumerable.
Example
set = Set[0, 1, 2] set | Set[2, 1, 'a'] # => Set[0, 1, 2, "a"] set | set # => Set[0, 1, 2]
Related: see Methods for Set Operations.