Module: FixnumExtensions::InstanceMethods
- Defined in:
- lib/extensions/fixnum.rb
Instance Method Summary collapse
Instance Method Details
#closest_fibonacci ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/extensions/fixnum.rb', line 3 def closest_fibonacci raise "No closest lower Fibonacci for integer < 2" if self < 2 last_n = 1 n = 1 acc = 0 while acc < self n = acc acc = n + last_n last_n = n end last_n end |