2012-05-26 76 views
1

之間移動屬性我有如何散列

hash1 = {:sym1 => "aaa", :sym2 => "bbb"} 
hash2 = {:sym20 => "ccc", :sym21 => "ddd"} 

如何使

hash1 = {:sym1 => "aaa"} 
hash2 = {:sym2 => "bbb", :sym20 => "ccc", :sym21 => "ddd"} 

回答

5
hash2[:sym2] = hash1.delete(:sym2) 
+1

或者使用hash2.merge! sym2:hash1.delete(:sym2) –