Ruby | Set merge() function
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:
# Ruby program to illustrate # the merge method # requires the set require "set" s1 = Set[ 1 , 2 , 3 ] s2 = Set[ 6 ] # merge method used puts s1.merge(s2) |
Output:
Set: {1, 2, 3, 6}
Example 2:
# Ruby program to illustrate # the merge method # requires the set require "set" s1 = Set[ 1 , 2 , 3 ] # merge method used puts s1.merge([ 9 , 10 , 12 ]) |
Output:
Set: {1, 2, 3, 9, 10, 12}
Please Login to comment...