On 5/14/08, Tim Wolak <tim.wolak / gmail.com> wrote:
> Hmm ok then maybe changing the keys is not what I need to do then.
>
> The reason I have skty and sktyny is that those are account names, sorry
> should have stated that earlier.

You can still use readable variable names in the code.  (What if you
wanted to run the same algorithm on two different accounts?).   A
better idea might be to name your hash @account_balances, and store
the account names as strings.

So I have a list of account numbers
> and their balances, all accounts listed 500 through 539 should have a
> key of skty and accounts with 540 through 550 should be sktyny.  All the
> account balances for skty should be combined into the value for skty
> and all the balances should be combined for teh value of sktyny.

So what about something like
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
  puts "#{name} has a balance of #{total}"
}



-Adam