From: Robert Dober Date: 2008-05-08T17:22:51+09:00 Subject: Re: changing hash key On Wed, May 7, 2008 at 7:00 PM, Tim Wolak wrote: > Sandro Paganotti wrote: > > This is not working because you're using a string called '@acctnum' > > instead of the content of the variable @acctnum inside both has_key? and > > merge functions > > > > First remove ' signs from that functions, next I suggest you to use > > symbols instead > > of variables for keys (@acctnum.to_sym instead of @acctnum) > > > > Bye > > > > sktylist = Hash.new("") > > if sktylist.has_key?('@acctnum') > > sktylist.merge!('@acctnum' => 'value') > > else > > sktylist[@acctnum] = [value] > > end > > sktylist.each { |key, value| puts "#{key} equals #{value}" > > } > > I've created the hash and can store all keys and values however I'm > trying += to add the balances which is value in the hash. So far the > accounts that have the same number are not being consolidated into one > key, value.... Can someone tell me what I'm doing wrong with this? > > > Thanks, > Tim > > sktylist = Hash.new("") > sktylist[@acctnum] += [value] > p sktylist > -- > Given the limited amount of information I have I would guess that you might doing this TypeError: can't convert Array into String wrong. HTH Robert -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein