views:

37

answers:

1
a[0] = {:id => '1234', :value => '37'}
a[1] = {:id => '4321', :value => '50'}
a[2] = {:id => '1122', :value => '50'}

From here I want to be able to check to see if a hash exists with :id => '4321' without having to loop through the array manually. Is there anything where I can do something like this: a.exists?(:id => '4321') ? I've tried a few things but can't seem to figure it out. Thanks!

+4  A: 

How about:

a.any? {|x| x[:id] == '4321' }

That will return true if the block returns true.

rjk
Perfect!! Thanks!
Bradley Herman