合并Ruby数组并在其中连接元素

时间:2014-03-26 19:33:29

标签: ruby

我有两个数组

arr1 = ["a","b","c","d"]
arr2 = ["e","f","g","h"]

我希望得到像这样的结果

arr3 = ["ae","bf","cg","dh"]

我怎么能在红宝石中做到这一点?

1 个答案:

答案 0 :(得分:2)

我使用#zip

arr1 = ["a","b","c","d"] 
arr2 = ["e","f","g","h"]
arr1.zip(arr2).map(&:join)
# => ["ae", "bf", "cg", "dh"]