Method: Columnize::Columnizer#arrange_by_row
- Defined in:
- lib/columnize/columnize.rb
#arrange_by_row(list, nrows, ncols) ⇒ Object
Given list, ncols, nrows, arrange the one-dimensional array into a 2-dimensional lists of lists organized by rows.
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_row((1..5).to_a, 3, 2) =>
[[1,2], [3,4], [5]],
119 120 121 |
# File 'lib/columnize/columnize.rb', line 119 def arrange_by_row(list, nrows, ncols) (0...nrows).map {|r| list[r*ncols, ncols] }.compact end |