将数组仅按一级推入红宝石中的数组 [英] Push array into array on ruby by just one level
本文介绍了将数组仅按一级推入红宝石中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出:
a = [[1,"a"],[2,"b"]]
b = [[3,"c"],[4,"d"]]
I想要将 a
转换为 [[1, a],[2, b] [3, c],[4 , d]]
。没有 +
怎么办?
I want to turn a
into [[1,"a"],[2,"b"][3,"c"],[4,"d"]]
. How can do this without +
? It creates a new array, which I want to avoid.
(a << b).flatten(1)
# => [1, "a", 2, "b", [3, "c"], [4, "d"]]
推荐答案
a.concat(b)
...............................
...............................
这篇关于将数组仅按一级推入红宝石中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文