Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Array#transpose

array.transpose → new_array

Transposes the rows and columns in an Array of Arrays; the nested Arrays must all be the same size:

Example
a = [[:a0, :a1], [:b0, :b1], [:c0, :c1]]
a.transpose # => [[:a0, :b0, :c0], [:a1, :b1, :c1]]
See also #to_s #union #to_h #uniq also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1