the only thing I understand with fibonacci it's that it adds the number from the previous number. This program was taken from my assignment. And it says "If you take all of those ones and zeros and add them together, you'll get the same answer you get when you run the code."

I really tried my best to understand how this code works but I failed. Can anyone out there who is so kind and explain to me in layman's term or in a way a dummy would understand what's happening on this code? I would really appreciate it so much. Please.

It's easy to see that the first two cases can be combined: if n is 0, the result is 0, if n is 1, the result is 1. That's the same as saying if n is 0 or 1, the result is the same as n. And "n is 0 or 1" is the same as "n is less than 2":

def fib(n)
return n if n < 2
fib(n-2) + fib(n-1)
end

There's nothing special about this, it's the exact translation of the recursive definition of the mathematical Fibonacci function.