Enumerable#find
、 Enumerable#find_all
そしてEnumerable#any?
以下に示すように行くのが良い方法です:
people = [{name:'Bob',id:'12'}, {name:'Sam',id:'25'}]
p people.find{ |i| i[:id] == '12' } # to find a single and first entry which satisfies the given condtion
# => {:name=>"Bob", :id=>"12"}
people = [{name:'Bob',id:'12'}, {name:'Sam',id:'25'},{name:'Max',id:'12'}]
p people.find_all{ |i| i[:id] == '12' } # to find a multiple entries which satisfies the given condtion
# => [{:name=>"Bob", :id=>"12"}, {:name=>"Max", :id=>"12"}]
people = [{name:'Bob',id:'12'}, {name:'Sam',id:'25'},{name:'Max',id:'12'}]
p people.any? { |i| i[:id] == '12' }
# => true