📜  红宝石 |设置子集?函数

📅  最后修改于: 2022-05-13 01:55:32.841000             🧑  作者: Mango

红宝石 |设置子集?函数

subset?()是 Ruby 中的一个内置方法,如果集合是给定集合的子集,则返回 true。

示例 1

# Ruby program to illustrate 
# the subset?() method 
   
# requires the set 
require "set"
   
s1 = Set[2, 12, 78, 10, 87, 98] 
s2 = Set[2, 10, 87]
   
# reset method used 
puts s2.subset?(s1)

输出

true

示例 2

# Ruby program to illustrate 
# the subset?() method 
   
# requires the set 
require "set"
   
s1 = Set[2, 12, 78, 10, 87, 98] 
s2 = Set[1, 2, 3]
   
# reset method used 
puts s2.subset?(s1)

输出

false