Issue #16039 has been updated by sawa (Tsuyoshi Sawada).


JustJosh (Joshua Stowers) wrote:
> @sawa - I 100% agree with what you are saying. I did a poor job expressing my concerns.
> 
> I am nervous that singling out array arguments in the abbreviated form could result in confusion and misuse. This is not a problem for `Range#cover?`, because a range cannot be composed of other ranges.
> 
> Since `Set#superset?` does not have an abbreviated form, there is less opportunity for misuse.

I understand your point. If that is a concern, then we can simply not allow the abbreviated form for `Array#cover?`; raise an argument error when the argument is not an array, which is probably what the original proposal in this thread assumed. This somewhat weakly brakes the analogy from `Range#cover?`, but it should not a big deal.

(And still, there is an alternative view to not worry about that too much, and just allow the abbreviated form.)

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

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