Module: MorseCode::Cacheable

Included in:
Decoder, Encoder
Defined in:
lib/morse_code/cacheable.rb

Instance Method Summary collapse

Instance Method Details

#cacheObject



5
6
7
# File 'lib/morse_code/cacheable.rb', line 5

def cache
  @cache ||= {}
end

#fetch(key) ⇒ Object



9
10
11
12
13
14
# File 'lib/morse_code/cacheable.rb', line 9

def fetch(key)
  return cache[key] if cache[key]
  value = yield
  cache[key] = value
  value
end