Ruby | Set merge() function
Last Updated :
07 Jan, 2020
The merge() is an inbuilt method in Ruby returns the new set after merging the passed objects into a set.
Syntax: s1_name.merge(object)
Parameters: The function accepts a mandatory parameter enumerable object which is to be merged for.
Return Value: It returns the new set after merging.
Example 1:
require "set"
s1 = Set[ 1 , 2 , 3 ]
s2 = Set[ 6 ]
puts s1.merge(s2)
|
Output:
Set: {1, 2, 3, 6}
Example 2:
require "set"
s1 = Set[ 1 , 2 , 3 ]
puts s1.merge([ 9 , 10 , 12 ])
|
Output:
Set: {1, 2, 3, 9, 10, 12}
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...