Craig Demyanovich
5/7/2008 6:28:00 PM
[Note: parts of this message were removed to make it a legal post.]
On Wed, May 7, 2008 at 1:43 PM, Tim Wolak <tim.wolak@gmail.com> wrote:
> I'm trying to insert account numbers into a hash and add the balances
> together that are stored in the value. Is there a reason this is not
> working?
>
> sktylist = Hash.new("")
> sktylist[@acctnum] += [value]
> p sktylist
According to docs for Hash.new, you're initializing the Hash and telling it
that the default value for any new elements is an empty string. Then, you
might be accessing the hash with a key that doesn't exist, so you're getting
that default value, the empty string. Then you're trying to concatenate an
array to it. I assume that you don't want to do that based on your problem
description. Maybe you want to do something like this (from an IRB session):
$ irb
>> h = Hash.new(0.0)
=> {}
>> h["a"] += 2.2
=> 2.2
>> h["a"] += 3
=> 5.2
>> h
=> {"a"=>5.2}
Regards,
Craig