Ruby | Array Join (*) method
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 arraya = ["abc", "xyz", "dog"] # declaring arrayb = ["cow", "cat", "dog"] # declaring arrayc = ["cat", "1", "dog"] # a concatenating bputs "concatenation of a and b : #{a * "toy"}\n\n" # a concatenating cputs "concatenation of a and c : #{c * 1}\n\n" # b concatenating cputs "concatenation of b and c : #{b * "cat_rat"}\n\n" |
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 arraya = ["abc", "xyz", "dog"] # declaring arrayb = ["cow", "cat", "dog"] # declaring arrayc = ["cat", "1", "dog"] # a concatenating bputs "concatenation of a and b : #{a * 2}\n\n" # a concatenating cputs "concatenation of a and c : #{a * 1}\n\n" # b concatenating cputs "concatenation of b and c : #{b * "34"}\n\n" # b concatenating cputs "concatenation of b and c : #{c * "toy"}\n\n" |
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


