From: Todd Benson Date: 2008-05-15T07:14:40+09:00 Subject: Re: changing hash key On Wed, May 14, 2008 at 1:35 PM, Adam Shelly wrote: > account_map = { > "sticky" => (500..539), > "stinky" => (540..550) > } > # fill @account_balances... > > account_summary= Hash.new > account_map.each{|name,range| > account_summary[name]= @account_balances.select{|act_num, balance| > range.include? (act_num) > } > } > account_summary.each{|name, subtotals| > total = subtotals.map{|act_num,balance|balance}.sum Just FYI to ruby nubies: The #sum method for addition in enumerables is available in libraries (included with Rails, for example), but not in ruby 1.8.6 itself. I don't know the status of ruby 1.9 on that one. Todd