Ruby on rails 具有多个条件的哈希数组中的Ruby搜索

Ruby on rails 具有多个条件的哈希数组中的Ruby搜索,ruby-on-rails,arrays,ruby,hash,Ruby On Rails,Arrays,Ruby,Hash,我试图用两种不同的条件查询哈希数组,但这不起作用: 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 有什么建议吗? 谢谢您还需要

我试图用两种不同的条件查询哈希数组,但这不起作用:

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
有什么建议吗?
谢谢

您还需要使用
&&
来代替
现在?
可以使用

array_list = [
  {type: 'sale', currency: 'CAD', price: '123'},
  {type: 'purchase', currency: 'CAD', price: '321'}
]

if array_list.any? { |pt| pt[:type] == 'sale' && pt[:currency] == 'CAD'}
  # your logic
end

您想要的是
pt[:type]=“sale”&&pt[:currency]=“CAD”
。Ruby中的赋值是单个
=
。select块中存在意外的逗号。