+是一个内置方法红 gems 返回一个包含这两个集合的所有元素的集合。两个集合中的公共元素都出现一次。 ‘+’方法充当联合运算。
用法: s1.name + s2.name
参数:该函数不带任何参数。
返回值:它返回一个新集合,其中包含这两个集合的所有元素。
示例 1:
#Ruby program to illustrate the + method
#requires the set
require "set"
s1
= Set[1, 2, 4] s2 = Set[1, 2, 3]
#+ method used
s3
= s1 + s2
#Prints the s3
puts s3
输出:
Set: {1, 2, 4, 3}
示例 2:
#Ruby program to illustrate the + method
#requires the set
require "set"
s1
= Set[1, 2, 4] s2 = Set[6, 5, 3]
#& method used
s3
= s1 + s2
#Prints the s3
puts s3
输出:
Set: {1, 2, 4, 6, 5, 3}
参考: https://devdocs.io/ruby~2.5/set#method-i-2B
相关用法
- Scala Set ++()用法及代码示例
- Scala Set +()用法及代码示例
- Scala Set head()用法及代码示例
- Scala Set max()用法及代码示例
- Scala Set dropWhile()用法及代码示例
- Scala Set apply()用法及代码示例
- Scala Set contains()用法及代码示例
- Scala Set copyToArray()用法及代码示例
- Scala Set count()用法及代码示例
- Scala Set diff()用法及代码示例
- Scala Set drop()用法及代码示例
- Scala Set dropRight()用法及代码示例
- Scala Set equals()用法及代码示例
- Scala Set exists()用法及代码示例
- Scala Set filter()用法及代码示例
- Scala Set find()用法及代码示例
- Scala Set forall()用法及代码示例
- Scala Set foreach()用法及代码示例
- Scala Set init()用法及代码示例
- Scala Set intersect()用法及代码示例
- Scala Set isEmpty()用法及代码示例
- Scala Set last()用法及代码示例
- Scala Set map()用法及代码示例
- Scala Set min()用法及代码示例
- Scala Set mkString()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 Ruby | Set + method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。