title: How to get the current index during recursive call
body: <p>I use the gem <code>ancestry</code> to create comments.</p>
  
  <p>Now, I can list all comments.</p>
  
  <p>But I want to push serial number to each comment.</p>
  
  <p>For example, if there were 3 comments, the first comment is annotated by 1, the next annotated by 2,..</p>
  
  <p>I have no idea how to do it?</p>
  
  <h2>show.html.haml</h2>
  
  <pre><code>- if notice
    %p.alert.alert-success= notice
  = nested_comments(@comment.subtree.arrange(:order =&gt; :created_at))
  </code></pre>
  
  <h2>helper</h2>
  
  <pre><code>  def nested_comments(comments)
      if comments.respond_to? :map
        comments.map do |comment, sub_comments|
          render(comment) + content_tag(:div, nested_comments(sub_comments), :class =&gt; "nested_comments")
        end.join.html_safe
      end
    end
  </code></pre>
  
  <h2>each_with_index won't work on recursive</h2>
  
  <p>if I have 4 comments, I want to show 0,1,2,3 for each comment</p>
  
  <p>But each_with_index can not make it because it's a recursive call.</p>
  
  <pre><code>comments.each_with_index.map do |(comment, sub_comments), i|
  </code></pre>
  
  <h2>comments</h2>
  
  <pre><code>=&gt; {#&lt;Comment id: 2, user_id: 1, ip: nil, content: "I'm id2 the second floor VIVOTEK Releases New Vers...", commentable_id: nil, commentable_type: nil, created_at: "2014-11-07 03:59:38", updated_at: "2014-11-07 06:56:12", ancestry: nil&gt;=&gt;
    {#&lt;Comment id: 4, user_id: 1, ip: nil, content: "lala", commentable_id: nil, commentable_type: nil, created_at: "2014-11-07 05:22:41", updated_at: "2014-11-07 05:22:41", ancestry: "2"&gt;=&gt;
      {#&lt;Comment id: 5, user_id: 1, ip: nil, content: "son of 4", commentable_id: nil, commentable_type: nil, created_at: "2014-11-07 06:38:04", updated_at: "2014-11-07 06:38:04", ancestry: "2/4"&gt;=&gt;
        {},
       #&lt;Comment id: 6, user_id: 1, ip: nil, content: "dild last 252", commentable_id: nil, commentable_type: nil, created_at: "2014-11-07 06:52:15", updated_at: "2014-11-07 06:52:15", ancestry: "2/4"&gt;=&gt;
        {}}}}
  </code></pre>