Flowdock

Good notes posted by ville

RSS feed
January 20, 2009 - (>= v2.2.1)
5 thanks

Reloading memoized values

Memoize is used to cache the result of a method. It’s roughly equivalent of having:

def memoized_method(*args)
  @result[args] ||= (
    # do calculation here
  )
end

However, the result is cached so that it’s not calculated for every request.

To recalculate cached value use either

obj.memoized_method(:reload)

or

obj.memoized_method(true)