Arrange an array aligned in columns vertically or horizontally.
Ruby Makefile
Permalink
Failed to load latest commit information.
lib 1st attempt to fix travis Dec 6, 2014
test DRY min_rows_and_colwidths tests. Apr 28, 2013
.gitignore Move lib/version.rb to lib/columnize/version.rb so version gem (versi… Dec 17, 2011
.travis.yml Disable Ruby 2.2.0 for now until we figure out how to add test/unit a… Apr 16, 2015
AUTHORS started refactoring vertical.rb; it's going to be harder than horizon… Mar 12, 2013
COPYING Split out arrange_rows and arrange_columns. Try to make COPYING consi… Apr 27, 2013
ChangeLog Update Changelog Dec 6, 2014
Gemfile Note that we use rdoc Apr 16, 2015
Makefile columnize.rb: some module function text got bolixed. Makefile: allow … Mar 9, 2013
NEWS Administrivia Dec 6, 2014
README.md README.md more Ruby example markup Apr 16, 2015
Rakefile Adminisrivia Mar 3, 2015
THANKS Get ready for release 0.8.9 Apr 19, 2014
columnize.gemspec

README.md

Build Status Gem Version

Columnize - Format an Array as a Column-aligned String

In showing a long lists, sometimes one would prefer to see the value arranged aligned in columns. Some examples include listing methods of an object, listing debugger commands, or showing a numeric array with data aligned.

Setup

    $ irb
    >> require 'columnize'
    => true

With numeric data

>> a = (1..10).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

>> a.columnize
=> "1  2  3  4  5  6  7  8  9  10"

>> puts a.columnize :arrange_array => true, :displaywidth => 10
[ 1, 2, 3,
  4, 5, 6,
  7, 8, 9,
 10]
=> nil

>> puts a.columnize :arrange_array => true, :displaywidth => 20
[1, 2, 3,  4, 5, 6,
 7, 8, 9, 10]
=> nil

With String data

>> g = %w(bibrons golden madascar leopard mourning suras tokay)
=> ["bibrons", "golden", "madascar", "leopard", "mourning", "suras", "tokay"]

>> puts g.columnize :displaywidth => 15
bibrons   suras
golden    tokay
madascar
leopard
mourning
=> nil

>> puts g.columnize :displaywidth => 19, :colsep => ' | '
bibrons  | mourning
golden   | suras
madascar | tokay
leopard
=> nil

>> puts g.columnize :displaywidth => 18, :colsep => ' | ', :ljust => false
bibrons | suras
 golden | tokay
madascar
 leopard
mourning
=> nil

Using Columnize.columnize

>> Columnize.columnize(a)
=> "1  2  3  4  5  6  7  8  9  10"

>> puts Columnize.columnize(a, :displaywidth => 10)
1  5   9
2  6  10
3  7
4  8
=> nil

>> Columnize.columnize(g)
=> "bibrons  golden  madascar  leopard  mourning  suras  tokay"

>> puts Columnize.columnize(g, :displaywidth => 19, :colsep => ' | ')
bibrons  | mourning
golden   | suras
madascar | tokay
leopard
=> nil

Credits

This is adapted from a method of the same name from Python's cmd module.

Other stuff

Authors: Rocky Bernstein rockyb@rubyforge.org endorse and Martin Davis

License: Copyright (c) 2011,2013 Rocky Bernstein

Warranty

You can redistribute it and/or modify it under either the terms of the GPL version 2 or the conditions listed in COPYING