Module: Caching

Defined in:
lib/caching.rb,
lib/caching/proxy.rb,
lib/caching/storage.rb,
lib/caching/version.rb

Defined Under Namespace

Classes: Proxy, Storage

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/caching.rb', line 5

def self.extended(klass)
  constructor = klass.method :new

  klass.define_singleton_method :new do |*args, &block|
    Proxy.new constructor.call(*args, &block), *@cached_methods
  end
end

Instance Method Details

#cache(*methods) ⇒ Object



13
14
15
# File 'lib/caching.rb', line 13

def cache(*methods)
  @cached_methods = (@cached_methods ||= []) | methods.map(&:to_sym).uniq
end