Class: Integer

Inherits:
Numeric
  • Object
show all
Defined in:
lib/closest_fib_gem.rb

Instance Method Summary collapse

Instance Method Details

#closest_fibonacciObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/closest_fib_gem.rb', line 8

def closest_fibonacci
  my_i = self.to_i

return nil if my_i == 0
return 0 if my_i == 1

a, b = 0, 1
while (b < my_i) do
	a, b = b, a+b
end 

a
end