[ruby-core:96226] [Ruby master Feature#16039] Array#contains? to check if one array contains another array
From:
daniel@...42.com
Date:
2019-12-14 01:33:41 UTC
List:
ruby-core #96226
Issue #16039 has been updated by Dan0042 (Daniel DeLorme). There's some similarity with #15198, to the point that I can re-use my suggestion from there: It might make sense to use ary1.to_set.superset?(ary2). That way it makes explicit the fact that ary1 must be converted to a set. But Set#superset? would have to support any Enumerable. ---------------------------------------- Feature #16039: Array#contains? to check if one array contains another array https://bugs.ruby-lang.org/issues/16039#change-83118 * 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>