我想从哈希数组中添加特定属性......这是一个示例数组:
@horses = [
{name: "Runner1", odds: 4.00},
{name: "Runner2", odds: 20.00},
{name: "Runner3", odds: 4.00}
]
我正在尝试这种方法:
@total_odds = horses[:odds].inject(:+)
但我收到一个错误:[ ]': can't convert Symbol into Integer
我究竟做错了什么?非常感谢(刚开始学习)