tags:

views:

79

answers:

2

I have the following:

array_of_hashes = [{:a=>10, :b=>20}, {:a=>11, :b=>21}, {:a=>13, :b=>23}]

How would I go about finding if :a=>11 exists in array_of_hashes

array_of_hashes.include? does not seem to work

+8  A: 
array_of_hashes.any? {|h| h[:a] == 11}
Magnar
+1  A: 

You did ask for a boolean result in the OQ, but if you really want the hash element itself do:

array_of_hashes.detect {  |h| h[:a] == 11 }
DigitalRoss