如何将数组中的哈希转换为ruby中的数组

如何将数组中的哈希转换为ruby中的数组,ruby,Ruby,我有一个数组,元素是散列 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 = [{: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) }