【发布时间】:2019-02-04 21:55:18
【问题描述】:
我正在尝试查询具有 2 个不同条件的哈希数组,但这不起作用:
array_list = [
{type: 'sale', currency: 'CAD', price: '123'},
{type: 'purchase', currency: 'CAD', price: '321'}
]
if array_list.select { |pt|
pt[:type] == 'sale', pt[:currency] == 'CAD'
}.present?
end
有什么建议吗? 谢谢
【问题讨论】:
-
你想要的是
pt[:type] == 'sale' && pt[:currency] == 'CAD'。 -
Ruby 中的赋值是单个
=。选择块中有一个意外的逗号。
标签: ruby-on-rails arrays ruby hash