Ruby on rails 如何展平阵列-但不是一直向下

Ruby on rails 如何展平阵列-但不是一直向下,ruby-on-rails,ruby,Ruby On Rails,Ruby,最好的转换方法是什么 [[["Club three Team one", 7800], ["Club three Team two", 7801]], [], [["Club four Team one", 7807], ["Club four Team two", 7808]], []] 进入 用红宝石?“展平”会将其一直转换为 ["Club three Team one", 7303, "Club three Team two", 7304, "Club four Team one", 7

最好的转换方法是什么

[[["Club three Team one", 7800], ["Club three Team two", 7801]], [], [["Club four Team one", 7807], ["Club four Team two", 7808]], []]
进入

用红宝石?“展平”会将其一直转换为

["Club three Team one", 7303, "Club three Team two", 7304, "Club four Team one", 7310, "Club four Team two", 7311]
使用
展平(1)


值得注意的是,对于较旧的Ruby版本:your_array.inject([],:concat)@tokland对于大型数组,这将非常有用slower@fl00r:Array#concat在Ruby中已就位,因此不会太慢。我做了一些测试,性能几乎相同。@tokland我认为
inject
是最慢的部分:)
["Club three Team one", 7303, "Club three Team two", 7304, "Club four Team one", 7310, "Club four Team two", 7311]
your_array = [[["Club three Team one", 7800], ["Club three Team two", 7801]], [], [["Club four Team one", 7807], ["Club four Team two", 7808]], []]
your_array.flatten(1)
#=> [["Club three Team one", 7800], ["Club three Team two", 7801], ["Club four Team one", 7807], ["Club four Team two", 7808]]