Ruby中从COUNTRIES = {
"DE" => {:currency => "EUR", :tax_rates => [19, 7], :languages => ["de-de"]},
"US" => {:currency => "USD", :tax_rates => [10], :languages => ["en-us"]}
}
通过以下嵌套哈希检索正确哈希的最快方法是什么:
currency
我设法通过提供COUNTRIES.select{|key, hash| hash[:currency] == "USD" }
:
language
但我如何通过en-us
进行查询,例如<div #someElement *ngIf="showElement">
some content
</div>
?
感谢您的帮助。
答案 0 :(得分:3)
COUNTRIES.select{|key, hash| hash[:languages].include?("en-us")}
#detect
比使用#select.first
更便宜