From: "Jesús Gabriel y Galán" Date: 2009-12-05T08:24:02+09:00 Subject: Re: Finding an element in an array of hashes On Fri, Dec 4, 2009 at 9:37 PM, Aldric Giacomoni wrote: > Alex Stupakov wrote: >> Hi, >> >> I have an array of Facebooker::User objects >> so friends.class => Array >> and friends[1].class => Facebooker::User >> >> Facebooker::User are objects which are basically hashes. >> friends[1].facebook.id.class => Integer >> >> I'd like to find the array member with a particular facebook_id. >> friends.find_by_id(12345) should return the corresponding >> Facebooker::User object >> >> What's the cleanest way to do this? >> Do I have to iterate over the array members or is there a method in Ruby >> that does this? > > "basically" hashes? That doesn't look like hash syntax to me.. > > friends.find { |friend| friend.facebook.id = 12345 } Careful, there should be a == there... Jesus.