title: Convert Ruby Hash into YAML
body: <p>I need to convert a hash like the one provided below into readable YAML. It looks like I can feed <code>YAML::load</code> a string, but I think I need to convert it first into something like this:</p>
  
  <pre><code>hostname1.test.com:
    public: 51
    private: 10
  
  {"hostname1.test.com"=&gt;
     {"public"=&gt;"51", "private"=&gt;"10"},
   "hostname2.test.com"=&gt;
     {"public"=&gt;"192", "private"=&gt;"12"}
  }
  </code></pre>
  
  <p>I'm not sure exactly how to do that conversion into that string effectively though. </p>
  
  <p>I looked through the HASH documentation and couldn't find anything for <code>to_yaml</code>. I found it by searching for <code>to_yaml</code> which becomes available when you <code>require yaml</code>. I also tried to use the Enumerable method <code>collect</code> but got confused when I needed to iterate through the value (another hash). </p>
  
  <p>I'm trying to use "<a href="https://stackoverflow.com/questions/1038275/converting-hash-to-string-in-ruby">Converting hash to string in Ruby</a>" as a reference. My thought was then to feed that into <code>YAML::load</code> and that would generate the YAML I wanted.</p>