From: "David A. Black" Date: 2008-08-20T20:32:09+09:00 Subject: Re: array of hashes - need to iterate and calulate stats but how Hi -- On Wed, 20 Aug 2008, Lex Williams wrote: > something like this : > > statistic_hash = {} > > array.each do |hash| > if(hash[:did_it_sell) > if(statistic_hash.has_key? hash[:title] > statistic_hash[hash[:title]] += 1 > else > statistic_hash[hash[:title]] = 0 > end > end > end > > and then you would have a statistic_hash containing as key a product > name , and as value , the number of units sold. I'm not sure about how > to calculate the statistics . You can use a hash with a default value to make all that hash testing easier: statistic_hash = Hash.new(0) array.each do |hash| next unless hash[:did_it_sell] statistic_hash[hash[:title]] += 1 end David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL See http://www.rubypal.com for details and updates!