1
A
回答
7
Enumerable#detect
是好的,但我認爲Enumerable#any?
(返回boolean),是嚴格的,你問什麼:
xs = [{:id => 1, :name => 'a'}, {:id => 2, :name => 'b'}]
puts xs.any? {|x| x[:id] == 1} # true
puts xs.any? {|x| x[:id] == 5} # false
3
嘗試detect
a = [{:id => 1, :name => 'a'}, {:id => 2, :name => 'b'}]
puts a.detect {|x| x[:id] == 1}
相關問題
- 1. 包括紅寶石
- 2. 紅寶石klout寶石包括變化
- 3. 兩個紅寶石陣列
- 4. 紅寶石陣列
- 5. 紅寶石模塊包括
- 6. 詞包括紅寶石
- 7. 如何包括紅寶石
- 8. 包括使用紅寶石
- 9. 迭代一個YAML陣列紅寶石
- 10. 紅寶石 - 在一個陣列
- 11. 紅寶石:確定是否一個陣列包括從用戶輸入
- 12. 紅寶石陣列範圍
- 13. 紅寶石陣列切片
- 14. 紅寶石陣列內部
- 15. 陣列中的紅寶石
- 16. 紅寶石陣列換行
- 17. 紅寶石發現陣列
- 18. 紅寶石陣列注入
- 19. 紅寶石陣列減法?
- 20. 紅寶石:生成陣列
- 21. 紅寶石:從陣列
- 22. 紅寶石YAML陣列
- 23. 拼合紅寶石陣列
- 24. 紅寶石從陣列
- 25. 紅寶石嵌套陣列
- 26. 轉換陣列,紅寶石
- 27. 紅寶石:在陣列
- 28. 合併紅寶石陣列
- 29. 紅寶石 - 陣列弄平
- 30. 紅寶石陣列平等
的可能重複[確定值存在於散列數組中](http://stackoverflow.com/questions/1514883/determine-if-a-value-exists-in-an-array-of-hashes) – 2011-12-12 22:03:44