I need to convert this array:
[:a, :b, :c, :d, :e]
Into this hash:
{:a=>{:b=>{:c=>{:d=>:e}}}}
Unfortunately, I'm missing the Recursion Lobe of the brain. I found BottomlessHash
# http://firedev.com/posts/2015/bottomless-ruby-hash/
class BottomlessHash < Hash
def initialize
super &-> h, k { h[k] = self.class.new }
end
end
While I'm struggling to understand the "pretzel stab", it does the trick if you write it out explicitly,
bhash = BottomlessHash.new
bhash[:a][:b][:c][:d] = :e
bhash # => {:a=>{:b=>{:c=>{:d=>:e}}}}
However I can't figure out a way to pass arbitrary values programmatically.
store doesn't work, nor does send("[:a][:b][:c][:d]=", :e)