2

I am trying to define a structure that can create a one-to-many relationship, sort of. For example, let's say an organization named "ACO" has some stuff:

KEY_PERF_INDS = [ {'ACO' => [2,3,4] , [2,34,5]} ]

But this is syntactically wrong. Is it possible to write something that achieves this?

5
  • 1
    Is ACO supposed to be an array of sub-arrays? 'ACO' => [ [2,3,4], [2,34,5] ] Commented Feb 17, 2013 at 19:24
  • yeah that looks good. So I want to be able to have one structure that says ACO ..these.... "HOSPITAL" ... those...."BLAH"...these...so I need one more layer around what you have, so I have many more of things like that "ACO" that them selves have many things like those numbers in the arryas Commented Feb 17, 2013 at 19:26
  • 1
    HOSPITAL,BLAH are at the same level as ACO? That's just more keys in the hash... [{ 'ACO' => [[2,3,4],[3,4,5]], 'HOSPITAL' => [[1,2,3],[9,8]] }] Commented Feb 17, 2013 at 19:30
  • Or, KEY_PERF_INDS itself should be a hash {} not an array. KEY_PERF_INDS = { 'ACO' => [[1,2,3],[4,5,6]], 'HOSPITAL' => [[3,2,1],[9,8,7]] } Commented Feb 17, 2013 at 19:31
  • @MichaelBerkowski : Yes, HOSPITAL, BLAH, ... all at the same level as "ACO".... Commented Feb 17, 2013 at 19:33

1 Answer 1

2

If your other groups HOSPITAL, BLAH, ETC (per the comments) are all to be at the same level as ACO, then the entire structure KEY_PERF_INDS should be a hash {} rather than an array []. Make each of those a key to the main hash, and each is an array containing sub-arrays.

# The main structure is a hash {}
KEY_PERF_INDS = { 
  'ACO' => [
    [1,2,3],
    [4,5,6]
  ], 
   'HOSPITAL' => [
    [3,2,1],
    [9,8,7]
  ],
  'BLAH' => [
    [99,88], 
    [11,22],
    [33,44]
  ]
}

Access these then as:

KEY_PERF_INDS['HOSPITAL'][1][2]
# prints 7

KEY_PERF_INDS['BLAH'].last.first
# prints 33
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.