> This is the usual iterative solution: > > class Integer > # not thread safe! > @@fib = [0, 1] > > def fib > for i in @@fib.length .. self > @@fib << @@fib[i - 1] + @@fib[i - 2] > end > @@fib[self] > end > end > > With a little more effort you can limit array size to two and prevent > the error I was seeing: like def fib nbr a0, a1 = 1, 0 (nbr-2).times{a1, a0 = a0, a0+a1} a0 end ? But this is way slower than the OPs one. cheers Simon