lib/caching.rb in caching-0.0.1 vs lib/caching.rb in caching-0.0.2
- old
+ new
@@ -4,10 +4,17 @@
def self.extended(klass)
constructor = klass.method :new
klass.define_singleton_method :new do |*args, &block|
- Proxy.new constructor.call(*args, &block), *@cached_methods
+ 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
def cache(*methods)
@cached_methods = (@cached_methods ||= []) | methods.map(&:to_sym).uniq
\ No newline at end of file