Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#to_table(*headers, **opts) ⇒ Object



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

def to_table(*headers, **opts)
  data = each_with_index.map do |(_key, item), index|
    ret = headers.map { |field| item.send(field) }
    ret[0] = "[#{index + 1}] #{ret[0]}" if opts[:with_index]
    ret
  end.uniq
  data.unshift(headers.map(&:upcase))
end