gpt4 book ai didi

ruby - 如何合并多个哈希?

转载 作者:数据小太阳 更新时间:2023-10-29 06:35:00 25 4
gpt4 key购买 nike

现在,我正在像这样合并两个哈希值:

department_hash  = self.parse_department html
super_saver_hash = self.parse_super_saver html

final_hash = department_hash.merge(super_saver_hash)

输出:

{: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}}

但是现在想以后合并更多。例如:

department_hash  = self.parse_department html
super_saver_hash = self.parse_super_saver html
categories_hash = self.parse_categories html

如何合并多个哈希?

最佳答案

怎么样:

[department_hash, super_saver_hash, categories_hash].reduce &:merge

关于ruby - 如何合并多个哈希?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18329633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com