Class: Fixnum
- Inherits:
-
Object
- Object
- Fixnum
- Defined in:
- lib/fibless.rb
Overview
Fibless – by Matt Holloway
Instance Method Summary collapse
-
#closest_fibonacci ⇒ Object
This will return the fibonacci sequence smaller than an integer passed in usage is x.closest_fibonacci where x is an integer greater than 0.
Instance Method Details
#closest_fibonacci ⇒ Object
This will return the fibonacci sequence smaller than an integer passed in usage is x.closest_fibonacci where x is an integer greater than 0
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fibless.rb', line 5 def closest_fibonacci if self < 0 return "Please enter a number of zero or greater, thanks" end #Three variables used for the sequence... fibCur = 0 #current number in the fib sequence fibNext = 1 #next number to add fibOut = fibCur #number we will display while fibCur < self && self > 1 fibCur = fibNext + fibOut fibOut = fibNext fibNext = fibCur end #ta-da, return the result fibOut end |