diff --git a/hw1/fibonacci.rb b/hw1/fibonacci.rb index e69de29..d60fdd0 100644 --- a/hw1/fibonacci.rb +++ b/hw1/fibonacci.rb @@ -0,0 +1,18 @@ +class Fibonacci + include Enumerable + + def initialize(length) + @length = length + end + + def each + prev_value = 1 + value = 1 + @length.times do + + yield prev_value + + prev_value, value = value, prev_value + value + end + end +end