Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3396 > unrolled thread

Recursive to check same key in has

Started bySiratinee Sukachai <ploy.sukachai@gmail.com>
First post2011-04-23 06:43 -0500
Last post2011-04-23 07:20 -0500
Articles 2 — 2 participants

Back to article view | Back to comp.lang.ruby


Contents

  Recursive to check same key in has Siratinee Sukachai <ploy.sukachai@gmail.com> - 2011-04-23 06:43 -0500
    Re: Recursive to check same key in has Brian Candler <b.candler@pobox.com> - 2011-04-23 07:20 -0500

#3396 — Recursive to check same key in has

FromSiratinee Sukachai <ploy.sukachai@gmail.com>
Date2011-04-23 06:43 -0500
SubjectRecursive to check same key in has
Message-ID<368cef391ff38f27093984a8ae8f8375@ruby-forum.com>
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. How to do that?

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [next] | [standalone]


#3398

FromBrian Candler <b.candler@pobox.com>
Date2011-04-23 07:20 -0500
Message-ID<920f4f632df8ad81f125de63f3ed8483@ruby-forum.com>
In reply to#3396
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 :-)

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web