Class: ClosestFib::Fibs
- Inherits:
-
Object
- Object
- ClosestFib::Fibs
- Defined in:
- lib/closestfib.rb
Constant Summary collapse
- @@fibs =
[0,1]
Class Method Summary collapse
- .all ⇒ Object
- .fib(n) ⇒ Object
- .flush ⇒ Object
- .last_fib ⇒ Object
- .next_fib ⇒ Object
- .prev_fib ⇒ Object
Class Method Details
.all ⇒ Object
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 |
.flush ⇒ Object
35 36 37 |
# File 'lib/closestfib.rb', line 35 def flush @@fibs = [0,1] end |
.last_fib ⇒ Object
23 24 25 |
# File 'lib/closestfib.rb', line 23 def last_fib @@fibs[@@fibs.length-1] end |
.next_fib ⇒ Object
19 20 21 |
# File 'lib/closestfib.rb', line 19 def next_fib @@fibs[@@fibs.length] = last_fib + prev_fib end |
.prev_fib ⇒ Object
27 28 29 |
# File 'lib/closestfib.rb', line 27 def prev_fib @@fibs[@@fibs.length-2] end |