Module: Memoizable::Copy

Defined in:
lib/standard/facets/memoizable.rb

Overview

Include Memoizable alone with an #initialize_copy method that will copy the memoization cache when #dup or #clone is used.

TODO: Is this best approach? Perhaps a method to easily create the #initialize_copy method would suffice?

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


128
129
130
# File 'lib/standard/facets/memoizable.rb', line 128

def self.included(base)
  base.extend(Memoizable)
end

Instance Method Details

#initialize_copy(original) ⇒ Object


133
134
135
136
137
# File 'lib/standard/facets/memoizable.rb', line 133

def initialize_copy(original)
  if Memoizable.cache.key?(original)
    Memoizable.cache[self] = Memoizable.cache[original].dup
  end
end