When you use flatten!, it could return a nil.  So what could happen is you could get "undefined method `[]' for nil:NilClass" before you can convert that to a string.