lib/active_object/hash.rb in active_object-5.1.1 vs lib/active_object/hash.rb in active_object-5.1.2
- old
+ new
@@ -65,10 +65,19 @@
self
end
# rubocop:enable Metrics/MethodLength
+ def demote(key)
+ return self unless key?(key)
+ merge(key => delete(key))
+ end
+
+ def demote!(key)
+ replace(demote(key))
+ end
+
def denillify(value = 0)
each { |key, val| self[key] = val.nil? ? value : val }
end
def denillify!(value = 0)
@@ -118,9 +127,18 @@
def only!(*keys)
hash = {}
keys.flatten.each { |key| hash[key] = self[key] if key?(key) }
replace(hash)
+ end
+
+ def promote(key)
+ return self unless key?(key)
+ { key => delete(key) }.merge(self)
+ end
+
+ def promote!(key)
+ replace(promote(key))
end
def rename_keys(*keys)
dup.rename_keys!(*keys)
end