Module: ClosestFib

Defined in:
lib/closestfib.rb

Overview

Written by Richard Nygord, Copyright © 2011 Created on 9/10/11 Find the closest fibonacci number less than n Adds method closest_fibonacci to Fixnum and Bignum

Defined Under Namespace

Classes: Error, Fibs

Class Method Summary collapse

Class Method Details

.closestfib(x) ⇒ Object

Raises:



41
42
43
44
45
46
# File 'lib/closestfib.rb', line 41

def self.closestfib x
  raise(Error, "no Fibonacci numbers are less than 0") if x <= 0
  n=0
  n+=1 while (Fibs.fib n) < x
  Fibs.fib n-1
end