Class: Fixnum
- Inherits:
-
Object
- Object
- Fixnum
- Defined in:
- lib/closest-fibonacci-gem.rb
Instance Method Summary collapse
Instance Method Details
#closest_fibonacci ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/closest-fibonacci-gem.rb', line 2 def closest_fibonacci if self < 0 return "Provide a positive integer or 0" end fibNum = 0 if self == 0 || self == 1 || self == 2 || self == 3 fibNum = self else n1 = 2 n2 = 3 while fibNum < self fibNum = n1 + n2 n1 = n2 n2 = fibNum end fibNum = n1 end return fibNum end |