最简单的方法是垂直合并这些数组

Aks*_*hat 0 ruby arrays ruby-on-rails

我有这些阿拉斯

names = ["Will","Bob","John","Ben"]
ages = [45,49,32,49]
postcodes = [9320,3991,1234,2993]
Run Code Online (Sandbox Code Playgroud)

什么是堆叠它们的最有效方式,因此它们显示为

people = [["Will",45,9320],["Bob",49,3991],["John",32,1234],["Ben",49,2993]]
Run Code Online (Sandbox Code Playgroud)

ruby是否具有垂直合并这些功能?(通过索引)漂亮而简单,没有所有那些讨厌的循环?

meg*_*gas 8

people = names.zip(ages, postcodes)

=> [["Will", 45, 9320], ["Bob", 49, 3991], ["John", 32, 1234], ["Ben", 49, 2993]]
Run Code Online (Sandbox Code Playgroud)