Does anyone know why this code:
sum=0
def get_sum n
return sum if n<1
sum=sum+n
get_sum(n-1)
end
get_sum 10
gives me this?
rb:3:in `get_sum': undefined local variable or method `sum' for main:Object (NameError)
from 1.rb:8:in `<main>'
The code makes perfectly sense, and you can understand what it is doing.