Class: Array

Inherits:
Object show all
Defined in:
lib/ext/core.rb

Instance Method Summary collapse

Instance Method Details

#to_tableObject



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/ext/core.rb', line 2

def to_table
  if self.first.is_a?( Hash )
    headings = self.first.keys
    Terminal::Table.new(
      :headings => headings,
      :rows => self.map { |r| headings.map { |h| r[h] } }
    ).to_s
  else
    Terminal::Table.new( :rows => self.map { |r| r.is_a?( Array ) ? r : [r] } ).to_s
  end
end