Class: Ki::HashCache

Inherits:
Hash show all
Defined in:
lib/util/hash_cache.rb

Overview

Caching Hash, resolves values at request time

Instance Method Summary collapse

Methods inherited from Hash

#require

Instance Method Details

#cache(key, &block) ⇒ Object

If key has not been defined, uses block to resolve the value. Value is stored and returned



24
25
26
27
28
29
# File 'lib/util/hash_cache.rb', line 24

def cache(key, &block)
  if !include?(key)
    store(key, block.call)
  end
  self[key]
end