title: How to instantiate a multilevel hash with an arbitrary depth
body: <p>I want to create a hash from the result of a database query such that its keys are the column values except the last one, and the value are the last column value (or a default value). For example, if I have rows:</p>
  
  <pre><code>1 2 3 1
  1 2 4 9
  1 3 2 nil
  </code></pre>
  
  <p>and a default value of <code>111</code>, I should get:</p>
  
  <pre><code>{
    1 =&gt; 
         {
            2 =&gt; { 3 =&gt; 1, 4 =&gt; 9},
            3 =&gt; { 2 =&gt; 111}
         }
  }
  </code></pre>
  
  <p>I want to make the method generic enough to handle an arbitrary number of columns, so the signature could be:</p>
  
  <pre><code>to_lookup(rows, default_value, value_column, *columns)
  </code></pre>
  
  <p>How would I go about that?</p>
  
  <p><strong>Update</strong>: forgot a comma in the output.</p>