Class: ClosestFib::Fibs

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

Constant Summary collapse

@@fibs =
[0,1]

Class Method Summary collapse

Class Method Details

.allObject



31
32
33
# File 'lib/closestfib.rb', line 31

def all
  @@fibs
end

.fib(n) ⇒ Object



14
15
16
17
# File 'lib/closestfib.rb', line 14

def fib n
  next_fib while ! @@fibs[n]
  @@fibs[n]
end

.flushObject



35
36
37
# File 'lib/closestfib.rb', line 35

def flush
  @@fibs = [0,1]
end

.last_fibObject



23
24
25
# File 'lib/closestfib.rb', line 23

def last_fib
  @@fibs[@@fibs.length-1]
end

.next_fibObject



19
20
21
# File 'lib/closestfib.rb', line 19

def next_fib
  @@fibs[@@fibs.length] = last_fib + prev_fib
end

.prev_fibObject



27
28
29
# File 'lib/closestfib.rb', line 27

def prev_fib
  @@fibs[@@fibs.length-2]
end