for i in xrange(n): result.append(a) a, b = b, a + b return result for a in fibonacci(20): print a def fibonacci(n): def fibonacci(n): result = [] def fibonacci(n): result = [] a = b = 1 for i in xrange(n): result.append(a) a, b = b, a + b return result def fibonacci(n): result = [] a = b = 1 for i in xrange(n): def fibonacci(n): result = [] a = b = 1 for i in xrange(n): result.append(a) a, b = b, a + b
a a, b = b, a + b end end def fibonacci(n) a = b = 1 n.times do yield a a, b = b, a + b end end return to_enum(__method__, n) unless block_given? ] [ Enumerable!