Skip to content
instance method

Array#-

(::_ToAry[untyped]) -> ::Array[Elem]
self - other_array → new_array

Returns a new array containing only those elements of self that are not found in other_array; the order from self is preserved:

Example
[0, 1, 1, 2, 1, 1, 3, 1, 1] - [1]             # => [0, 2, 3]
[0, 1, 1, 2, 1, 1, 3, 1, 1] - [3, 2, 0, :foo] # => [1, 1, 1, 1, 1, 1]
[0, 1, 2] - [:foo]                            # => [0, 1, 2]

Element are compared using method eql? (as defined in each element of self).

Related: see Methods for Combining.

See also #+ #<< #* #<=> also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0