Method: Columnize::Columnizer#arrange_by_column

Defined in:
lib/columnize/columnize.rb

#arrange_by_column(list, nrows, ncols) ⇒ Object

Given list, ncols, nrows, arrange the one-dimensional array into a 2-dimensional lists of lists organized by columns.

In either horizontal or vertical arrangement, we will need to access this for the list data or for the width information.

Here is an example: arrange_by_column((1..5).to_a, 2, 3) =>

[[1,3,5], [2,4]]


133
134
135
136
137
138
139
140
# File 'lib/columnize/columnize.rb', line 133

def arrange_by_column(list, nrows, ncols)
  (0...ncols).map do |i|
    (0..nrows-1).inject([]) do |row, j|
      k = i + (j * ncols)
      k < list.length ? row << list[k] : row
    end
  end
end