Module: Caching
- Defined in:
- lib/caching.rb,
lib/caching/proxy.rb,
lib/caching/storage.rb,
lib/caching/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.extended(klass) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/caching.rb', line 5 def self.extended(klass) constructor = klass.method :new klass.define_singleton_method :new do |*args, &block| instance = constructor.call(*args, &block) proxy = Proxy.new instance, *@cached_methods instance.send :define_singleton_method, :clear_cache do proxy.clear_cache end proxy end end |
Instance Method Details
#cache(*methods) ⇒ Object
20 21 22 |
# File 'lib/caching.rb', line 20 def cache(*methods) @cached_methods = (@cached_methods ||= []) | methods.map(&:to_sym).uniq end |