ruby inject recursion?
- by Matt Humphrey
the goal is to start with ['a','b','c'] and end up with {'a'={'b'={'c'={}}}}
so, getting my bearings, i did this:
ruby-1.8.7-p174 ['a','b','c'].inject({}){|h,v| h.update(v = {})}
= {"a"={}, "b"={}, "c"={}}
and then figured, if i actually pass on the result hash, it will recurse and nest, but:
ruby-1.8.7-p174 ['a','b','c'].inject({}){|h,v| h.update(v = {}); h[v]}
= {}
why is this? any idea how to achieve the desired result in an elegant one-liner?