Convert Array of Hashes to Hash!

In your Ruby on Rails project, you can override array.rb file and add few good methods there πŸ€

i.e. - convert array of hashes to hash.

Path - lib/array.rb

⚠️ Don't forget to require it in application.rb

Code snippet πŸ“Œ

def convert_to_hash
  Hash[self.map(&:values).map(&:flatten)] rescue {}
end

❯ array = [{ key: 1, value: 'one' }, { key: 2, value: 'two' }]
❯ array.convert_to_hash
❯ { 1 => "one", 2 => "two" }