okay, something reads a little overly-complicated about the code, and it could at least do with a comment above it all...

maybe just a .sub(/#{scheme}:\/\//, '') if you're just trying to strip off the scheme?

could also feed it into URI.parse and if it parses, then extract the hostname + port from the object which might have other good encoding/decoding things that happen...