Ruby | Set merge() function Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 # 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 # 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} Comment More infoAdvertise with us Next Article Ruby | Hash merge! function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Set-class Similar Reads Ruby | Set intersect?() function The intersect?() is an inbuilt method in Ruby returns true if the set and the given set have at least one element in common. Syntax: s1_name.intersect?(s2_name) Parameters: The function accepts a mandatory parameter set with whom it is checked for. Return Value: It returns true if the set and the gi 1 min read Ruby | Hash merge function Hash#merge() is a Hash class method which combines two hash arrays and their content. Syntax: Hash.merge() Parameter: Hash values Return: combine two hash arrays Example #1 : Ruby # Ruby code for Hash.merge() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, 2 min read Ruby | Hash merge! function Hash#merge!() : merge!() is a Hash class method which can add the content the given hash array to the other. Entries with duplicate keys are overwritten with the values from each other_hash successively if no block is given. Syntax: Hash.merge!() Parameter: Hash values Return: add the content the gi 2 min read Ruby | Set intersection() function The intersection() is an inbuilt method in Ruby that returns a set which contains the common elements in both the set. In case there are no common elements, it returns an empty set. Syntax: s1.name.intersection(s2.name) Parameters: The function does not takes any parameter. Return Value: It returns 1 min read Ruby | Regexp ===() function Regexp#===() : ===() is a Regexp class method which compares the equality of two regular expressions. Syntax: Regexp.===() Parameter: Regexp values Return: true - if two regular expressions has equality otherwise return false Example #1 : Ruby # Ruby code for Regexp.===() method # declaring Regexp v 1 min read Ruby | Regexp ==() function Regexp#==() : ==() is a Regexp class method which compares two regular expressions. Syntax: Regexp.==() Parameter: Regexp values Return: true - if two regular expressions are equal otherwise return false Example #1 : Ruby # Ruby code for Regexp.==() method # declaring Regexp value reg_a = /a/ # decl 1 min read Like