From: Craig Demyanovich Date: 2008-05-08T03:27:35+09:00 Subject: Re: hash adding values ------=_Part_783_6845416.1210184834552 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Wed, May 7, 2008 at 1:43 PM, Tim Wolak 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 ------=_Part_783_6845416.1210184834552--