From: Glen Holcomb Date: 2008-07-15T06:32:05+09:00 Subject: Re: array of hashes (finding value) ------=_Part_62353_25540703.1216071343562 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, Jul 14, 2008 at 3:22 PM, Nate Leavitt wrote: > I'm just looking for other possible solutions. Sorry, this is kinda a > noob question. > > Currently I loop through the array and check the value of each hash key > to find values. Is that the only and/or best way to find matches? > > example: > > @invoices = [{:id => 1, :first_name => 'nate'}, {:id => 2, :fist_name => > 'greg'}, {:id => 3, :first_name =>}] > > @invoices.each do |invoice| > if invoice[:id] == params[:contact_id] > bla... bla... > end > end > -- > Posted via http://www.ruby-forum.com/. > > With the construct you have there it would be faster to just store the names in an array at the index corresponding to :id. Although if this is coming out of Rails that probably isn't a viable option. If you are stuck with that construct then what you have should work fine. There are probably faster/more efficient ways though. -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_62353_25540703.1216071343562--