Style Nitpick:
multi-line blocks should use do/end
you probably don't need .nil? because nil from a missing key is falsy already