对于看起来像这样的数组:
arr = [["name1","name2","name3"],["address1","address2","address3"],["phone1","phone2","phone3"]]
我想重新安排它,看起来像:
arr = [["name1","address1","phone1"],["name2","address2","phone2"], ...
目前的方法是:
name = arr[0]
add = arr[1]
phone = arr[2]
arr = name.zip(add,phone)
有效,但是当我在一个数组中有十多个嵌套数组时,我有十行定义哪个,以后再使用zip。
我希望有人能告诉我更好的处理方式。
编辑:
我最初有#34; Phone1"," Phone2",作为我的初始数组(大写)和" phone1"," phone2"作为我的转置数组。
这不是故意的,所以我编辑了它,但是在我原来的帖子中,Sawa的回答处理了转置&大写为小写。
此处还找到了文档:
http://www.ruby-doc.org/core-2.1.2/Array.html#method-i-transpose