Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Set#difference
(::_Each[A]) -> self
difference(p1)
set.c
View on GitHub ↗
static VALUE
set_i_difference(VALUE set, VALUE other)
{
return set_i_subtract(rb_obj_dup(set), other);
}
Alias of #-
Returns a new set containing the difference of self and argument enumerable; that is, containing all elements in self that are not in enumerable.
Example
set = Set[*(0..6), *%w[ a b c]] # => Set[0, 1, 2, 3, 4, 5, 6, "a", "b", "c"] set - ['b', 6, 4, 1] # => Set[0, 2, 3, 5, "a", "c"] set - ['d', 7, 9] # => Set[0, 1, 2, 3, 4, 5, 6, "a", "b", "c"]
Related: see Methods for Set Operations.