Module: ForgetMeNot::Memoizable

Defined in:
lib/forget-me-not/memoizable.rb

Overview

Allows the memoization of method calls

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/forget-me-not/memoizable.rb', line 5

def included(base)
  base.extend(ClassMethods)
end

.storage_builderObject



73
74
75
# File 'lib/forget-me-not/memoizable.rb', line 73

def storage_builder
  @storage_builder ||= Proc.new {HashCache.new}
end

.storage_builder=(builder) ⇒ Object



77
78
79
# File 'lib/forget-me-not/memoizable.rb', line 77

def storage_builder=(builder)
  @storage_builder = builder
end

Instance Method Details

#fetch_from_storage(key, &block) ⇒ Object



64
65
66
# File 'lib/forget-me-not/memoizable.rb', line 64

def fetch_from_storage(key, &block)
  storage.fetch(key, &block)
end

#storageObject



68
69
70
# File 'lib/forget-me-not/memoizable.rb', line 68

def storage
  @storage ||= Memoizable.storage_builder.call
end