title: Ruby Recursion Counter Without Global Variable
body: <p>I am trying to count the number of times the method recurses during the life of the program. The code below gets the desired result, but uses global variables. Is there a way around this or a better way? </p>
  
  <pre><code>$count = 0
  def AdditivePersistence(num)
    return 0 if num.to_s.length == 1  
    numarr = num.to_s.chars.map!(&amp;:to_i)
    i = numarr.inject(&amp;:+)
    $count+=1
      if i.to_s.length!=1
      AdditivePersistence(i)
      end
    $count
  end
  </code></pre>