Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Set#difference

difference(enum)

Alias of #-

Returns a new set built by duplicating the set, removing every element that appears in the given enumerable object.

Example
Set[1, 3, 5] - Set[1, 5]                #=> #<Set: {3}>
Set['a', 'b', 'z'] - ['a', 'c']         #=> #<Set: {"b", "z"}>
See also #- #delete_if #disjoint? #delete? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1