Array#*() is an Array class method which performs set join operation on the arrays. And returns new array by concatenation of int copies of the self.
Syntax: Array.*()
Parameter: Arrays for performing the join or concatenation operation.
Return: New arrays with concatenated int copies of self
Example #1 :
# Ruby code for *() method # showing join operation # declaring array a = ["abc", "xyz", "dog"] # declaring array b = ["cow", "cat", "dog"] # declaring array c = ["cat", "1", "dog"] # a concatenating b puts "concatenation of a and b : #{a * "toy"}\n\n" # a concatenating c puts "concatenation of a and c : #{c * 1}\n\n" # b concatenating c puts "concatenation of b and c : #{b * "cat_rat"}\n\n" |
chevron_right
filter_none
Output :
concatenation of a and b : abctoyxyztoydog concatenation of a and c : ["cat", "1", "dog"] concatenation of b and c : cowcat_ratcatcat_ratdog
Example #2 :
# Ruby code for *() method # showing join operation # declaring array a = ["abc", "xyz", "dog"] # declaring array b = ["cow", "cat", "dog"] # declaring array c = ["cat", "1", "dog"] # a concatenating b puts "concatenation of a and b : #{a * 2}\n\n" # a concatenating c puts "concatenation of a and c : #{a * 1}\n\n" # b concatenating c puts "concatenation of b and c : #{b * "34"}\n\n" # b concatenating c puts "concatenation of b and c : #{c * "toy"}\n\n" |
chevron_right
filter_none
Output :
concatenation of a and b : ["abc", "xyz", "dog", "abc", "xyz", "dog"] concatenation of a and c : ["abc", "xyz", "dog"] concatenation of b and c : cow34cat34dog concatenation of b and c : cattoy1toydog
Recommended Posts:
- Ruby | Array class join() function
- Ruby | Array ==() method
- Ruby | Array <<() method
- Ruby | Array min() function
- Ruby | Array zip() function
- Ruby | Array pop() function
- Ruby | Array max() function
- Ruby | Array map() function
- How to initialize array in Ruby
- Ruby | Array none?() function
- Ruby Array () function with example
- Add array elements in Ruby
- Ruby | Array map!() operation
- Ruby | Array at() operation
- Ruby | Array take() function
- Ruby | Array one?() function
- Ruby | Array any?() operation
- Ruby | Array &() function
- Ruby | Array <=> function
- Ruby | Array dig() operation
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.

