Issue #16039 has been updated by shevegen (Robert A. Heiler).


I think the use case is ok - you want to find out whether an Array or
an Array-like object, is contained in another object (container in a 
container in a container ...).

My biggest problem with this is that #contains? is similar in meaning
to #include?, even though they do slightly different things. (By the way
I think for consistency, it would have to be #contain? rather than
#contains?, similar to #include? rather than #includes?).

I am not sure if superset is a better name; to me it conveys a different
meaning than #contains?; but one advantage that superset may have is
that it would not conflict with e. g. #include?, whereas I feel that
#contains? would do so more.

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

#contains? would be simpler to read in your example indeed :) - but
I think it could lead to ruby users wondering when to use #include?
and when to use e. g. #contain?, and I am not sure this would be 
good. We already have people wondering when to use strings and when
to use symbols in a Hash. Keeping things simple(r) would be good,
IMO. ;)

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

* 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>