如何在方法中传递嵌套哈希?这是一个示例代码
MONOPOLY_GAME = {
deeds:
{
boardwalk:
{
price: 400,
rent: 50
},
atlantic:
{
price: 260,
rent: 22
},
baltic:
{
price: 60,
rent: 4
}
}
}
def rent_for(p)
return MONOPOLY_GAME[:deeds][:p][:rent]
end
rent_for(:boardwalk)
rent_for(:atlantic)
rent_for(:baltic)
答案 0 :(得分:5)
您的方法似乎是正确的,除了您必须从p
中删除冒号def rent_for(p)
MONOPOLY_GAME[:deeds][p][:rent]
end