Sha256: 35daaa3cfe5b528fe7afd66fc354ea8526db1a42af87fd0d1985497b0ac07a3d
Contents?: true
Size: 922 Bytes
Versions: 14
Compression:
Stored size: 922 Bytes
Contents
module R10K # R10K::Registry implements a generic object memoization container. It caches # new objects and returns cached objects based on the instantiation arguments. class Registry # Initialize a new registry with a given class # # @param klass [Class] The class to memoize # @param method [Symbol] The method name to use when creating objects. # Defaults to :new. def initialize(klass, method = :new) @klass = klass @method = method @instances = {} end # Create a new object, or return a memoized object. # # @param args [*Object] The arguments to pass to the initialize method # # @return [Object] A memoized instance of the registered class def generate(*args) @instances[args] ||= @klass.send(@method, *args) end # Clear all memoized objects def clear! @instances = {} end end end
Version data entries
14 entries across 14 versions & 1 rubygems