Issue #16039 has been updated by cha1tanya (Prathamesh Sonpatki).


Agree that `superset` is better name. Here is the actual use case:

```ruby
Project.pluck(:id).contains?([1,2,3])
```

Where `Project.pluck` returns an array of integers. 

To use set, I have to convert the array to a set.

```ruby
Project.pluck(:id).to_set.superset?(Set[1,2,3])
```

I wanted to avoid creating Set objects just for the purpose of this check so my motivation was to have such method on Array.

----------------------------------------
Feature #16039: Array#contains? to check if one array contains another array
https://bugs.ruby-lang.org/issues/16039#change-80377

* Author: cha1tanya (Prathamesh Sonpatki)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I woud like to propose `Array#contains?` which will check if the one array is part of another array.
Implementation can be as follows:

```
def contains?(other)
  (other - self).empty?
end
```

Some test cases:

```
[1, 2, 3].contains?([2, 3]) => true
[1, 2, 3].contains?([]) => true
[1, 2, 3].contains?([1, 2, 3, 4]) => false
[].contains?([]) => true
[].contains?([1, 2, 3, 4]) => false
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>