From: Peter Bailey Date: 2007-02-16T22:16:58+09:00 Subject: Re: Iterating through 2 fields for one hash, or array. Alex Young wrote: > Peter Bailey wrote: >>> >>> @cost_centers = Hash.new(0) >>> def add_to_cost_centers(center_key, amount) >>> @cost_centers[center_key] += amount >>> end >>> >>> Hope this helps, >> > >> @cost_centers = Hash.new(0) >> def add_to_cost_centers(center_key, amount) >> @cost_centers[center_key] += amount >> end >> >> testcount_tbl.select(:costcenter, :pagecount).each do |x| >> add_to_cost_centers(x.costcenter, x.pagecount) >> puts x >> end > What happens when you put: > > p @cost_centers > > after this? I get a half pyramid of data, like this, all the way down for about 150 entries. What I want, of course, is a single column of unique cost center entries, with page count totals for each. But, at least I'm getting something. Thanks for your help, Alex. I'll keep you abreast of any progress. {"ADAM00"=>8} {"CBCD00"=>8, "ADAM00"=>8} {"CBCD00"=>8, "EDDG00"=>8, "ADAM00"=>8} {"CBCD00"=>8, "EDDG00"=>8, "JOSH00"=>4, "ADAM00"=>8} {"CBCD00"=>8, "EDDG00"=>8, "JOSH00"=>4, "ADAM00"=>8, "HCCG00"=>4} . . . -- Posted via http://www.ruby-forum.com/.