module Columnize
def self.columnize(*args)
* whether to format as an array - with surrounding [] and
* whether to left justify text instead of right justify
* whether to ignore terminal codes in text size calculation
* A format specify for formatting each item each array item to a string
* a line suffix
* a line prefix
* a column separator
* the line display width
separated by two spaces. Options are available for setting
Each column is only as wide as necessary. By default, columns are
]
09, 10,
07, 08,
05, 06,
03, 04,
[01, 02,
:displaywidth => 10) =>
puts (1..10).to_a.columnize(:arrange_array => true, :colfmt => '%02d',
Formatted as an array using format specifier '%02d':
['1', '2,', '3', '4'] => '1 2\n3 4\n'
a.columnize(:arrange_vertical => false) =>
Arranged horizontally:
a.columnize => '1 3\n2 4\n'
Alternatively:
Columnize.columnize(a) => '1 3\n2 4\n'
a = (1..4).to_a
For example, for a line width of 4 characters (arranged vertically):
that when printed the columns are aligned.
Return a string from an array with embedded newlines formatted so
Columnize.columize([args]) => String
def self.columnize(*args) list = args.shift opts = parse_columnize_options(args) Columnizer.new(list, opts).columnize end