Module: Lisbn::CacheMethod

Included in:
Lisbn
Defined in:
lib/lisbn/cache_method.rb

Instance Method Summary collapse

Instance Method Details

#cache_method(*methods) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/lisbn/cache_method.rb', line 3

def cache_method(*methods)
  methods.map(&:to_s).each do |method|
    alias_method method + "_without_cache", method
    define_method method do |*args, &blk|
      @cache ||= {}
      @cache[[method, args, blk, self]] ||= send(method + "_without_cache", *args, &blk)
    end
  end
end