4
有数组元素的哈希我如何散列转换成阵列阵列中的红宝石
a = [{:history_date=>"15/07/10"}, {:open_price=>"7.90"}]
我想转换到这个
h = {:history_date=>"15/07/10", :open_price=>"7.90"}
有人请帮助我。
有数组元素的哈希我如何散列转换成阵列阵列中的红宝石
a = [{:history_date=>"15/07/10"}, {:open_price=>"7.90"}]
我想转换到这个
h = {:history_date=>"15/07/10", :open_price=>"7.90"}
有人请帮助我。
如何:
h = a.inject(&:merge)
阵列中的每个哈希合并到以前的哈希,直到我们踏踏实实地一个元素。 &:merge
是以下内容的简写,可能会比较容易理解,但稍长:
h = a.inject { |all, element| all.merge(element) }