I have an array of strings of unknown length (but let's say up to 5). I have also an empty hash h = {} and a value.
I want to transform the array and the value to hash like this:
val = 1
h = {}
a = ['a', 'b', 'c', 'd']
# result I want:
{
'a' => {
'b' => {
'c' => {
'd' => 1
}
}
}
}
What's important is that some of the keys might already exist (created in a loop iteration before). So I might have:
val = 2
h = {'a' => {'b' => {'c' => {'d' => 1}}}}
a = ['a', 'b', 'c', 'e']
# result I want:
{
'a' => {
'b' => {
'c' => {
'd' => 1,
'e' => 2
}
}
}
}
Any ideas on how to do that?