当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Ruby Set disjoint?用法及代码示例


脱节?是Ruby中的内置方法,如果set和给定set没有共同的元素,则返回true。

用法:s1.disjoint?(s2)

参数:该函数不带任何参数。


返回值:它通过复制集合,删除出现在给定可枚举对象中的每个元素,来返回一个新集合。

例子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


相关用法


注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 Ruby | Set disjoint? function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。