How to merge multiple hashes?
hash, ruby
Solution
You can do below way using `Enumerable#inject`:
h = {}
arr = [{:a=>"b"},{"c" => 2},{:a=>4,"c"=>"Hi"}]
arr.inject(h,:update)
# => {:a=>4, "c"=>"Hi"}
arr.inject(:update)
# => {:a=>4, "c"=>"Hi"}
Problem
Right now, I'm merging two hashes like this: ``` department_hash = self.parse_department html super_saver_hash = self.parse_super_saver html final_hash = department_hash.merge(super_saver_hash) ``` Output: {:department=>{"Pet Supplies"=>{"Birds"=>16281, "Cats"=>245512, "Dogs"=>513926, "Fish & Aquatic Pets"=>46811, "Horses"=>14805, "Insects"=>364, "Reptiles & Amphibians"=>5816, "Small Animals"=>19769}}, :super_saver=>{"Free Super Saver Shipping"=>126649}} But now I want to merge more in the future. For example: ``` department_hash = self.parse_department html super_saver_hash = self.parse_super_saver html categories_hash = self.parse_categories html ``` How to merge multiple hashes?