Class: StellarSpectrum::Fibo

Inherits:
Object
  • Object
show all
Defined in:
lib/stellar_spectrum/services/fibo.rb

Class Method Summary collapse

Class Method Details

.call(n) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/stellar_spectrum/services/fibo.rb', line 4

def self.call(n)
  return n if n <= 1

  @cache ||= {}
  cached_value = @cache[n]
  return cached_value unless cached_value.nil?

  @cache[n] = self.(n-1) + self.(n-2)
end