A
Adam Akhtar
Hi Ive done a search on this and there have been quite a few posts which
have incresed my knowlege somewhat but still have a few questions.
Im creating a hash of arrays. The keys and values are added within a
loop. For each key there may be multiple values hence the need for an
array as a value. Values for a key are found over interations of a loop.
I therefore have to append a new found value to the existing values in
an array.
I tried doing this
something.each do |blah|
if (test something)
hash[key] = hash[key] + value
end
end
but the compliler complains about there being no method for nil class.
I read the basic way to do this would be
hash[key] = [] #create blank array
hash[key] = hash[key] + value
but as im in a loop that would require me to do a check to see if the
key exists or not. If im processing lots of informatino that would slow
me down a bit.
IS there a slicker way of doing this?
have incresed my knowlege somewhat but still have a few questions.
Im creating a hash of arrays. The keys and values are added within a
loop. For each key there may be multiple values hence the need for an
array as a value. Values for a key are found over interations of a loop.
I therefore have to append a new found value to the existing values in
an array.
I tried doing this
something.each do |blah|
if (test something)
hash[key] = hash[key] + value
end
end
but the compliler complains about there being no method for nil class.
I read the basic way to do this would be
hash[key] = [] #create blank array
hash[key] = hash[key] + value
but as im in a loop that would require me to do a check to see if the
key exists or not. If im processing lots of informatino that would slow
me down a bit.
IS there a slicker way of doing this?