Sha256: 81f0dbeded4ba3f742ced37769f95306b9a9f3e89653f966bd2f01df83e98f9e
Contents?: true
Size: 1.01 KB
Versions: 5
Compression:
Stored size: 1.01 KB
Contents
module Vedeu module Repositories # Some classes expect a certain set of attributes when # initialized, this module uses the #defaults method of the class # to provide missing attribute keys (and values). # # @api private # module Defaults # Returns a new instance of the class including this module. # # @note # If a particular key is missing from the attributes # parameter, then it is added with the respective value from # #defaults. # # @param attributes [Hash] # @return [void] A new instance of the class including this # module. def initialize(attributes = {}) attrs = attributes.to_h.keep_if { |key, _| defaults.key?(key) } defaults.merge!(attrs).each do |key, value| instance_variable_set("@#{key}", value || defaults.fetch(key)) end end private # @return [Hash<void>] def defaults {} end end # Defaults end # Repositories end # Vedeu
Version data entries
5 entries across 5 versions & 1 rubygems