Reputation: 12933
I have an array arr = ["test", "test 1", "test 2"]
. How would I print test, test 1, test 2.
? Note the "."
and the ","
in the expected output.
I know how to iterate over this by doing:
arr.each do |a|
puts a
end
but I'm not sure how to get the expected output.
Upvotes: 0
Views: 90
Reputation: 118299
You can do this way also using Array#*
which says :-
Repetition — With a String argument, equivalent to ary.join(str).
arr = ["test", "test 1", "test 2"]
arr*" ," << "."
# => "test ,test 1 ,test 2."
Upvotes: 1