class Hash

Public Instance Methods

to_table(*headers, **opts) click to toggle source
# 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