Class: Fixnum
- Inherits:
-
Object
- Object
- Fixnum
- Defined in:
- lib/kren-fib.rb
Instance Method Summary collapse
Instance Method Details
#closest_fibonacci ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/kren-fib.rb', line 2 def closest_fibonacci @first, @second = 0, 1 return nil if self == @first return @first if self == @second 1.upto(self) do |i| break if @second >= self @first, @second = @second, @first + @second end @first end |