给定两个散列,我试图将第一个散列中的一个值替换为第二个散列也具有的键。具体来说,我有这两个哈希:
data = {
"study" => "Lucid Study",
"name" => "Lucid Plan",
"studyWillBe" => "Combination"
}
conditions = { "study" => "((current))" }
我想更新data
它的"study"
密钥,因为conditions
有那个密钥。我想data
这样结束:
data = {
"study" => "((current))",
"name" => "Lucid Plan",
"studyWillBe" => "Combination"
}
我做到了这一点:
data = Hash[data.map {|k, v| [conditions[k] || k, v] }]
但这并不完全奏效。谁能指出我正确的方向?