Module: Yogurt::Memoize

Instance Method Summary collapse

Instance Method Details

#freezeObject



26
27
28
29
30
31
# File 'lib/yogurt/memoize.rb', line 26

def freeze
  @memoized_values = T.let(@memoized_values, T.nilable(T::Hash[Symbol, T.untyped]))
  @memoized_values&.freeze
  super
  self
end

#memoize_as(name, &block) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/yogurt/memoize.rb', line 16

def memoize_as(name, &block)
  memoized_values = @memoized_values
  memoized_values = @memoized_values = {} if memoized_values.nil?

  return memoized_values[name] if memoized_values.key?(name)

  memoized_values[name] = yield
end