add-memberalign-toparrow-leftarrow-rightbellblockcalendarcamerachatchevron-leftchevron-rightchevron-small-downchevron-upcircle-with-crosscomposecrossfacebookflagfolderglobegoogleimagesinstagramkeylocation-pinmedalmoremuplabelShape 3 + Rectangle 1pagepersonpluspollsImported LayersImported LayersImported LayersshieldstartwitterwinbackClosewinbackCompletewinbackDiscountyahoo

Nested Hashes/Hash of Hashes in Ruby

From: user 1.
Sent on: Tuesday, March 9, 2010 6:49 PM

I have got a question regarding the Hash table in ruby on rails.
I am trying to create a 3-D hashes (hash of hashes) and loop each line of mybuffer to parse the data and dump into the hash of hashes.

For say, here is my sample data:

groupid fnam lname bday?
1 abc xyz jan1
def lmn feb1
2 amy morgan may1
nick cary may6

Here is a sample code..?

myhash = {
my_buffer,each |line|
# use the parser to get the groupid, fname, lname bday
myhash = {groupid=>{fnam=>{"lname"=>lname, "bday"=>bday}}}

Now the problem I am seeing is when i print "myhash" at the end of the function, it just prints only the last line of "mybuffer".?

How can I store all the parsed information in a 3-D Hash table?

Any input is highly appreciated.
Thanks in advance,

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy