Recursive to check same key in has

h1 = {project=>{opp=>{Index=>{title=>Opportunities}}}}
h2 = {project=>{opp=>{Index=>{link=>Report}}}}

I need to check same key in hash and group the value to assign to the
same key of hash.

h = {project=>{opp=>{Index=>{title=>Opportunities, link=>Report}}}}

How to do that?

This is a case where recursion may be helpful.

However, based on your other posting, I think you may be trying to solve
the wrong problem.

If you’re trying to combine

project.opp.Index.title=Opportunities
project.opp.Index.link=Report

into a single nested hash, then you don’t need to build separate nested
hashes and then combine them. I think it would be easier to build the
final hash up-front, as you read in each new line.

Of course, doing a deep-merge of a nested hash structure is an
interesting exercise, or homework problem :slight_smile:

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