This was a problem, which i solved:
@cache={}
@cache[1]=0
@cache[2]=1
def fib(n)
@fibs[n-1]
end
def fib_m(n)
@cache[n] ||= fib_m(n-1) + fib_m(n-2)
end
@fibs=[]
@fibs=(1..100000).map{|n| fib_m(n)}
But this looks hacky. It seems like I am doubling the caching, and I have to hard code some upper limit. Is there a cleaner way to do this?