红宝石 |设置脱节?函数
脱节?是 Ruby 中的一个内置方法,如果集合和给定集合没有共同元素,则返回 true。
Syntax: s1.disjoint?(s2)
Parameters: The function does not takes any parameter.
Return Value: It returns a new set built by duplicating the set, removing every element that appears in the given enumerable object.
示例 1 :
# Ruby program to illustrate the disjoint? method
# requires the set
require "set"
s1 = Set[1, 2, 4]
s2 = Set[1, 2, 3]
# difference method used
s3 = s1.disjoint?(s2)
# Prints the s3
puts s3
输出:
false
示例 2 :
# Ruby program to illustrate the disjoint? method
# requires the set
require "set"
s1 = Set[8, 5, 4]
s2 = Set[1, 2, 3]
# difference method used
s3 = s1.disjoint?(s2)
# Prints the s3
puts s3
输出:
true