红宝石 |设置proper_subset?()函数
正确的子集?是 Ruby 中的一个内置方法,如果一个集合是另一个集合的真子集,则返回 true。如果它不是真子集,则返回 false。
Syntax: s1.name.proper_subset?(s2.name)
Parameters: The function does not takes any parameter.
Return Value: It returns true if set s1 is a proper subset of s2, else it returns false.
示例 1 :
# Ruby program to illustrate the proper_subset? method
# requires the set
require "set"
s1 = Set[1, 2]
s2 = Set[1, 2, 3]
# proper_subset method used
puts s1.proper_subset?(s2)
输出:
true
示例 2 :
# Ruby program to illustrate the proper_subset? method
# requires the set
require "set"
s1 = Set[1, 5]
s2 = Set[1, 2, 3]
# proper_subset? method used
puts s1.proper_subset?(s2)
输出:
false