I like method shown here – https://stackoverflow.com/a/9648410/1646893 and I want to use it in my case.
What if we have something like this:
{"a"=>{"b"=>"111", "c"=>"9", "d"=>{"ff"=>{"uu"=>[{"q"=>"77", "r"=>{"w"=>"66"}, "j"=>{"@l"=>"44"}}, {"q"=>"78", "r"=>{"w"=>"67"}, "j"=>{"@l"=>"45"}}]}, "@e"=>"56"}, "@b1"=>"01", "@b2"=>"02", "@b3"=>"03"}}
And When I tried to use our method:
{["a", "b"]=>"111", ["a", "c"]=>"9", ["a", "d", "ff", "uu"]=>[{"q"=>"77", "r"=>{"w"=>"66"}, "j"=>{"@l"=>"44"}}, {"q"=>"78", "r"=>{"w"=>"67"}, "j"=>{"@l"=>"45"}}], ["a", "d", "@e"]=>"56", ["a", "@b1"]=>"01", ["a", "@b2"]=>"02", ["a", "@b3"]=>"03"}
The result was an array with 2 values:
[{"q"=>"77", "r"=>{"w"=>"66"}, "j"=>{"@l"=>"44"}}, {"q"=>"78", "r"=>{"w"=>"66"}, "j"=>{"@l"=>"44"}}]
This is what i want to get:
["a", "d", "ff", "uu", "q0", "w0", "j0", "@l0"]=>"44"
etc.
Maybe I should change key names before using flat_hash method?
What should i do to have the result without an array and key names contain?
Here’s my answer that produces what I believe is a better output that what you are asking for. If you absolutely desperately need exactly the output you have asked for, say so and perhaps I’ll provide a variation that produces it.
Seen in action: