class Hash def reverse_merge(other_hash) other_hash.merge(self) end def reverse_merge!(other_hash) replace(reverse_merge(other_hash)) end def deep_transform_keys(&block) result = {} each do |key, value| result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value end result end def deep_transform_keys!(&block) keys.each do |key| value = delete(key) self[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys!(&block) : value end self end end