module Locale::Util::Memoizable

Constants

MEMOIZED_IVAR

Public Class Methods

included(base) click to toggle source
# File lib/locale/util/memoizable.rb, line 14
def self.included(base)
  mod = self
  base.class_eval do
    extend mod
  end
end

Public Instance Methods

memoize(*symbols) click to toggle source

Cache the result of the methods.

include Memoizable
def foo
  ......
end
def bar(a, b)
  ......
end
memoize :foo, :bar(a, b)

To clear cache, clear_foo, clear_bar is also defined.

(NOTE)

  • Consider to use this with huge objects to avoid memory leaks.

  • Can't use this with super.<method> because of infinity loop.

# File lib/locale/util/memoizable.rb, line 55
def memoize(*symbols)
  memoize_impl(false, *symbols)
end
memoize_clear() click to toggle source

Clear memoized values.

# File lib/locale/util/memoizable.rb, line 35
def memoize_clear
  @_memoized_ivars = {}
end
memoize_dup(*symbols) click to toggle source

memoize with dup. A copy object is returned.

# File lib/locale/util/memoizable.rb, line 60
def memoize_dup(*symbols)
  memoize_impl(true, *symbols)
end