相关疑难解决方法(0)

Sum 2使用相同的键散列属性

我有2个哈希,例如:

{'a' => 30, 'b' => 14}
{'a' => 4, 'b' => 23, 'c' => 7}
Run Code Online (Sandbox Code Playgroud)

其中a,bc都是对象.我怎样才能将这些哈希的密钥加起来得到一个新的哈希:

{'a' => 34, 'b' => 37, 'c' => 7}
Run Code Online (Sandbox Code Playgroud)

ruby hash attributes sum

40
推荐指数
2
解决办法
9356
查看次数

标签 统计

attributes ×1

hash ×1

ruby ×1

sum ×1