class Array

Public Instance Methods

merge_hashes() click to toggle source

Merges an Array of Hases into a single Hash, keeping duplicate values in an Array

Raises StandardError if the Array is not an Array of Hashes, exclusively

# File lib/gimme_wikidata/extensions.rb, line 36
def merge_hashes
  raise StandardError.new "Array is not an Array of Hashes" unless self.all? {|e| e.is_a? Hash}
  self.each_with_object({}) do |el, h|
    el.each { |k, v| h[k] = h[k] ? [*h[k]] << v : v }
  end
end