[ruby-core:96225] [Ruby master Feature#16039] Array#contains? to check if one array contains another array

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-83117.20191214005804.bab94422c91c0cc3@ruby-lang.org>
Issue #16039 has been updated by JustJosh (Joshua Stowers).


sawa (Tsuyoshi Sawada) wrote:
> by analogy from `Range`, `cover?` may be a better name.

I was never a fan of the name `cover?`, but the verbiage is still applicable here and it is better to be consistent.

In my opinion, the method should also accept non-array arguments.
For example:
``` ruby
[1, 2, 3].cover? 1, 2 # => true
```






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

* 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:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.