From: "David A. Black" Date: 2008-08-20T21:51:04+09:00 Subject: Re: array of hashes - need to iterate and calulate stats but how Hi -- On Wed, 20 Aug 2008, Lex Williams wrote: > David A. Black wrote: >> Hi -- >> >> On Wed, 20 Aug 2008, Lex Williams wrote: >> >>> 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 > > you could use select on the array , and lose those if's . something like > this : What if's? You mean the unless? 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!