我想通過哈希中的一個鍵合併兩個哈希陣列。舉例來說,如果我有:合併兩個哈希陣列
local = [{:name => 'foo', :values => [2, 7], :desc => 'my foo'}, {:name => 'bar', :values => [3, 8], :desc => 'my bar'}]
remote = [{:name => 'baz', :values => [4, 1], :desc => 'this baz'}, {:name => 'foo', :values => [5, 7], :desc => 'this foo'}]
我想合併爲:
[{:name => 'foo', :values => [2, 5, 7], :desc => 'my foo'}, {:name => 'bar', :values => [3,8], :desc => 'my bar'}, {:name => 'baz', :values => [4,1], :desc => 'this baz'}]
我怎樣才能做到這一點?
其中的價值':desc'你想合併後保留..? –
爲什麼'{:name =>'foo',:values => [2,5,7],:desc =>'my foo'}'not'{:name =>'foo',:values => [ 2,5,7],:desc =>'這個foo'}'? –