title: what's the best way to convert a ruby hash to an array
body: <p>I have a ruby hash that looks like this</p>
  
  <pre><code>{ "stuff_attributes" =&gt; {
       "1" =&gt; {"foo" =&gt; "bar", "baz" =&gt; "quux"}, 
       "2" =&gt; {"foo" =&gt; "bar", "baz" =&gt; "quux"} 
     }
  }
  </code></pre>
  
  <p>and I want to turn it into a hash that looks like this</p>
  
  <pre><code>{ "stuff_attributes" =&gt; [
      { "foo" =&gt; "bar", "baz" =&gt; "quux"},
      { "foo" =&gt; "bar", "baz" =&gt; "quux"}
    ]
  }
  </code></pre>
  
  <p>I also need to preserve the numerical order of the keys, and there is a variable number of keys. The above is super-simplified, but I've included a real example at the bottom. What's the best way to do this?</p>
  
  <p>P.S</p>
  
  <p>It also needs to be recursive</p>
  
  <p>As far as the recursion goes, here's what we can assume:</p>
  
  <p>1) the key that needs to be manipulated will match /_attributes$/
  2) the hash will have many other keys that do not match /_attributes$/
  3) the keys inside the hash will always be a number
  4) an _attributes hash can be at any level of the hash under any other key</p>
  
  <p>this hash is actually the params hash from a create action in the controller. This is a real example of what will need to be parsed with this routine.</p>
  
  <pre><code>{
      "commit"=&gt;"Save", 
      "tdsheet"=&gt;{
      "team_id"=&gt;"43", 
      "title"=&gt;"", 
      "performing_org_id"=&gt;"10", 
      "tdsinitneed_attributes"=&gt;{ 
          "0"=&gt;{
              "title"=&gt;"", 
              "need_date"=&gt;"", 
              "description"=&gt;"", 
              "expected_providing_organization_id"=&gt;"41"
              }, 
          "1"=&gt;{
              "title"=&gt;"", 
              "need_date"=&gt;"", 
              "description"=&gt;"", 
              "expected_providing_organization_id"=&gt;"41"
              }
          }, 
          "level_two_studycollection_id"=&gt;"27", 
          "plan_attributes"=&gt;{
              "0"=&gt;{
                  "start_date"=&gt;"", "end_date"=&gt;""
              }
          }, 
          "dataitem_attributes"=&gt;{
              "0"=&gt;{
                  "title"=&gt;"", 
                  "description"=&gt;"", 
                  "plan_attributes"=&gt;{
                      "0"=&gt;{
                          "start_date"=&gt;"", 
                          "end_date"=&gt;""
                          }
                      }
                  }, 
              "1"=&gt;{
                  "title"=&gt;"", 
                  "description"=&gt;"", 
                  "plan_attributes"=&gt;{
                      "0"=&gt;{
                          "start_date"=&gt;"", 
                          "end_date"=&gt;""
                          }
                      }
                  }
              }
          }, 
      "action"=&gt;"create", 
      "studycollection_level"=&gt;"", 
      "controller"=&gt;"tdsheets"
  }
  </code></pre>