Nested hash itself

Is there a way to create a nested hash with the same hash?

if I have a hash h1 = {‘key’ => ‘value’}

Can I do that h1[‘abc’] = h1
so I will end up with the following hash h1 = ( ‘abc’ => {‘key’ => ‘value’}}

Found it

I need to clone the hash

tmph = {}
tmph[key] = h.clone
h.clear
h = tmph.clone

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs