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) }