File: 08_table.md

package info (click to toggle)
ruby-ansi 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 404 kB
  • sloc: ruby: 1,880; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 451 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# ANSI::Table

The ANSI::Table class can be used to output tabular data with nicely
formated ASCII cell borders.

    require 'ansi/table'

The constructor takes an 2-dimensional array.

    data = [
      [ 10, 20, 30 ],
      [ 20, 10, 20 ],
      [ 50, 40, 20 ]
    ]

    table = ANSI::Table.new(data)

    table.to_s

The output will be:

    +----+----+----+
    | 10 | 20 | 30 |
    | 20 | 10 | 20 |
    | 50 | 40 | 20 |
    +----+----+----+