title: Recursive Fibonacci in Ruby
body: <p>This week is my first time doing recursion. One of the problems I was able to solve was Fibonacci's sequence to the nth number; it wasn't hard after messing with it for 5 minutes. </p>
  
  <p>However, I am having trouble understanding why this works with the current return statement. </p>
  
  <pre><code>return array if num == 2
  </code></pre>
  
  <p>If I push to array, it doesn't work, if I make a new variable sequence and push to that, it returns the correct answer. I am cool with that, but my base case says return array, not sequence. I initially pushed the sequence to the array, the result was not fibs sequence. I only solved the problem when I tried seeing what would happen if I pushed to the sequence array.</p>
  
  <p>Instead of just making it work I was hoping someone could explain what was happening under the hood, what the stacks might be and how the problem works. </p>
  
  <p>I understand recursion to an extent and somehow intuitively can make it work by assuming things, but I feel funny not actually knowing all the whys behind it. </p>
  
  <pre><code>def fib_seq(num)
    return [0] if num == 1
    return [] if num == 0
  
    array = [0, 1]
    return array if num &lt;= 2 
  
    seq = fib_seq(num - 1)  
    seq &lt;&lt; seq[-2] + seq[-1]
  end 
  </code></pre>