Array#+() is a Array class method which performs set concatenate operation arrays by combining two arrays to a third array.
Syntax: Array.+()
Parameter: Arrays for performing the concatenation operation.
Return: New arrays by combining two arrays.
Example #1 :
# Ruby code for +() method # showing concatenate operation # declaring array a = [18, 22, 33, 4, 5, 6] # declaring array b = [5, 4, 22, 1, 88, 9] # declaring array c = [18, 22, 33, 40, 50, 6] # combining arrays puts "combination of a and b : #{a + b}\n\n" # combining arrays puts "combination of a and c : #{a + c}\n\n" # combining arrays puts "combination of b and c : #{b + c}\n\n" |
chevron_right
filter_none
Output :
combination of a and b : [18, 22, 33, 4, 5, 6, 5, 4, 22, 1, 88, 9] combination of a and c : [18, 22, 33, 4, 5, 6, 18, 22, 33, 40, 50, 6] combination of b and c : [5, 4, 22, 1, 88, 9, 18, 22, 33, 40, 50, 6]
Example #2 :
# Ruby code for +() method # showing concatenate operation # declaring array a = ["abc", "xyz", "dog"] # declaring array b = ["cow", "cat", "dog"] # declaring array c = ["cat", "1", "dog"] # combining arrays puts "combination of a and b : #{a + b}\n\n" # combining arrays puts "combination of a and c : #{a + c}\n\n" # combining arrays puts "combination of b and c : #{b + c}\n\n" |
chevron_right
filter_none
Output :
combination of a and b : ["abc", "xyz", "dog", "cow", "cat", "dog"] combination of a and c : ["abc", "xyz", "dog", "cat", "1", "dog"] combination of b and c : ["cow", "cat", "dog", "cat", "1", "dog"]
Recommended Posts:
- Ruby | Array assoc() function
- Ruby | Array abbrev() function
- Ruby Array () function with example
- Ruby | Array class first() function
- Ruby | Array class flatten() function
- Ruby | Array class flatten!() function
- Ruby | Array class inspect() function
- Ruby | Array class hash() function
- Ruby | Array class index() function
- Ruby | Array class insert() function
- Ruby | Array class to_s() function
- Ruby | Array class join() function
- Ruby | Array class last() function
- Ruby | Array append() function
- Ruby | Array Difference (-) function
- Ruby | Array sort!() function
- Ruby | Array uniq() function
- Ruby | Array uniq!() function
- Ruby | Array unshift() function
- Ruby | Array values_at() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

