Also using `.sub!` instead of `.sub` saves on extra object allocations:

```ruby
def add_trailing_slash(path)
  if path.include?('?')
    # Includes query sting
    path.sub!(/\?/, '/\&')
  elsif !path.include?('.')
    # Does not have a .format
    path.sub!(/[^\/]\z|\A\z/, '\&/')
  end

  path
end
```