I'd find this easier to read as:
```
if uri.default_port == uri.port
  "#{url}:#{uri.port}"
else
  url
end
```