Module: Terminal::Table::TableHelper
- Included in:
- Object
- Defined in:
- lib/terminal-table/table_helper.rb
Instance Method Summary collapse
-
#table(headings = [], *rows, &block) ⇒ Object
Generates a Terminal::Table object.
Instance Method Details
#table(headings = [], *rows, &block) ⇒ Object
Generates a Terminal::Table object.
Examples:
puts table(['a', 'b'], [1, 2], [3, 4])
# OR
t = table ['a', 'b']
t << [1, 2]
t << [3, 4]
puts t
# OR
user_table = table do |t|
t.headings = 'First Name', 'Last Name', 'Email'
t << ['TJ', 'Holowaychuk', '[email protected]']
t << ['Bob', 'Someone', '[email protected]']
t << ['Joe', 'Whatever', '[email protected]']
end
puts user_table
# OR
user_table = table do
self.headings = 'First Name', 'Last Name', 'Email'
add_row ['TJ', 'Holowaychuk', '[email protected]']
add_row ['Bob', 'Someone', '[email protected]']
add_row ['Joe', 'Whatever', '[email protected]']
end
puts user_table
# OR
rows = []
rows << ['Lines', 100]
rows << ['Comments', 20]
rows << ['Ruby', 70]
rows << ['JavaScript', 30]
puts table(nil, *rows)
48 49 50 |
# File 'lib/terminal-table/table_helper.rb', line 48 def table headings = [], *rows, &block Terminal::Table.new :headings => headings.to_a, :rows => rows, &block end |