title: Ruby / Rails: determine how deeply nested an object is
body: <p>I think this is a general ruby question, though in my case the objects involved are ActiveRecord models.</p>
  
  <p>If I have a model that can be nested inside of another model, how can I determine how deeply nested the model is?</p>
  
  <p>IE:</p>
  
  <pre><code>Model Root (Level 0)
  - Model Level 1
  - - Model Level 2
  - - Model Level 2
  - - Model Level 2
  - - - Model Level 3
  - - - Model Level 3
  - Model Level 1
  - Model Level 1
  </code></pre>
  
  <p>In let's say <code>foo</code> is a model nested three levels deep (as shown above). If I call <code>foo.parent.parent.parent</code> I would get the root model.</p>
  
  <p>How could I define a method like: <code>foo.depth</code> that would return how many levels there are between foo and its root?</p>
  
  <p>Thanks!</p>