In this thread: there are many good examples of how to replace a key within a hash without changing the value.
This current question differs in that it is relating to a multi-dimensional hash. This may be trivial for those of you with more experience, but for a newbie rubyist it has been quite confusing!
Given:
{"2008"=>{"1" => {"ebook"=>"1"}}, "a"=>{"1" => {"man"=>"1", "distressed"=>"1"}}
Assuming I have "NEW_KEY", I would like to achieve:
{"2008"=>{"1" => {"ebook"=>"1"}}, "a"=>{"NEW_KEY" => {"man"=>"1", "distressed"=>"1"}}
This is part of a wider attempt to loop through the inner hashes to try to figure out the number of occurrences of a word.
In the above example I would like to set "2" as the key for "a" as "a" has the neighbours "man" and "distressed" one time.
Thanks in advance for any insights.
UPDATE:
Of course, being tired I had not clocked that you can go one layer deeper into the Hash and then the approach is the same as has been linked to in the other SO thread.
Out of interest life became much easier when someone suggested using Structs