`metadata_vals[k].nil? ? '' : metadata_vals[k]` can just be `metadata_vals[k] || ''`, I think.

It might also be more straightforward (and, fwiw, more efficient) to use `map` into a hash:

```ruby
unsaved_hash = Hash[unsaved_keys.map {|k| [k, metadata_vals[k] || ''] }]
```