title: print out Hash key and value pairs recursively
body: <p>I am trying to define a function that it can print out any hash values in a tree format. The function will do something like this:</p>
  
  <p>From    </p>
  
  <pre><code>{"parent1"=&gt;
      {"child1" =&gt; { "grandchild1" =&gt; 1,
                  "grandchild2" =&gt; 2},
      "child2" =&gt; { "grandchild3" =&gt; 3,
                  "grandchild4" =&gt; 4}}
  }
  </code></pre>
  
  <p>To </p>
  
  <pre><code>   parent1:
          child1: 
                grandchild1:1
                grandchild2:2
          child2:
                grandchild3:3
                grandchild4:4
  </code></pre>
  
  <p>And this is my code so far: </p>
  
  <pre><code>def readprop(foo)
      level = ''
      if foo.is_a?(Hash)
          foo.each_key {|key| if foo[key].nil? == false
                  puts level + key + ":"
                  level += "   "
                  readprop(foo[key])
              end 
          }
      else
          puts level + foo
          level = level[0,level.length - 2]
      end
  end 
  </code></pre>
  
  <p>and it will give me a bad format like this:</p>
  
  <pre><code>parent1:
  child1:
  grandchild1:
  1
     grandchild2:
  2
     child2:
  grandchild3:
  3
     grandchild4:
  4
  </code></pre>