Class: Array

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

Instance Method Summary collapse

Instance Method Details

#merge_hashesObject

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



36
37
38
39
40
41
# 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