From: Alex Young Date: 2007-02-16T05:12:04+09:00 Subject: Re: Iterating through 2 fields for one hash, or array. Peter Bailey wrote: > Alex Young wrote: >> Peter Bailey wrote: >>> DER000 128 >>> Cost Center Page Count >>> TMUS00 96 >>> ER0000 42 >>> DER000 192 >> I don't know the syntax for getting the data out of KirbyBase, but the >> trick I usually use for this sort of thing is a hash with a default >> value. Something like: >> >> @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? -- Alex