Very similar to this question, but in Ruby.
I have a nested hash (below is a NON literal example), and I have an array that points to my deepest child value:
ab0:
ad1:
ab0:
ad1: {}
ad1:
ab0:
ad1:
ab0: {}
The array that points to the last key "ab0" is [1,0,0,0]. I would like to use this array to traverse the hash by pointing to hash[1][0][0][0].
I will be using this hopefully to get each key used on the path to the child in question. My result should be:
keysUsed(hash, [1,0,0,0]) = [hash.keys[1], hash.keys[1].keys[0], hash[1].keys[0].keys[0]]
hash.keys[1]refer to:ab0and not:ad1?0ignored? Shouldn't there behash[1].keys[0].keys[0].keys[0]at the end? Are the keys hashes as well?[1,0,0,0], you have given an array with 3 (why?) elements:hash.keys[1],hash.keys[1].keys[0]andhash[1].keys[0].keys[0]but only the first one produces a result. Maybe the second element should behash[hash.keys[1]].keys[0]? Please clarify.