Sha256: b051450b7f3a98dc85a425607750b6093e1df42a00a19d9aaa91bd8fc0e5526a
Contents?: true
Size: 1001 Bytes
Versions: 4
Compression:
Stored size: 1001 Bytes
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Extensions #:nodoc: module Hash #:nodoc: module Accessors #:nodoc: # Remove a set of attributes from a hash. If the attributes are # contained in an array it will remove it from the array, otherwise it # will delete the child attribute completely. def remove(key, attrs) elements = self[key] if elements key.singular? ? self[key] = nil : elements.delete(attrs) end end # Inserts new attributes into the hash. If the elements are present in # the hash it will update them, otherwise it will add the new # attributes into the hash as either a child hash or child array of # hashes. def insert(key, attrs) elements = self[key] if elements elements.merge!(attrs) else self[key] = key.singular? ? attrs : [attrs] end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems