dimanche 14 janvier 2018

Merging multi-level hash in to a Single hash

I have a source hash:

a = {'1' => 'A', '2' => 'B', '3' => 'C', '4' => { '5' => 'D', '6' => 'E', '7' => { '8' => 'F', '9' => 'G' }}, '10' => {'11' => 'H'}}

I need to construct a method to make it a flat hash (single hash). I have seen ways at which we can merge 2 hashes (using deep_merge!) but I need to merge the above given hash. Please suggest a solution!

Aucun commentaire:

Enregistrer un commentaire