Sha256: 099cd4c1ecc9f816534ed44a642de98d3ae3432bcf37cb2cf614c22af248db05
Contents?: true
Size: 585 Bytes
Versions: 4
Compression:
Stored size: 585 Bytes
Contents
## # Helper module for caching methods inside a class # To use, extend your class with MethodCacher # Then, in initialize, call enable_caching module MethodCacher ## # Enable caching for the listed methods def enable_caching(methods, cache = nil) cache ||= BasicCache.new methods.each do |name| uncached_name = "#{name}_uncached".to_sym (class << self; self; end).class_eval do alias_method uncached_name, name define_method(name) do |*a, &b| cache.cache(name) { send uncached_name, *a, &b } end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems