Skip to content

Instantly share code, notes, and snippets.

@atomical
Created January 28, 2014 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomical/8673207 to your computer and use it in GitHub Desktop.
Save atomical/8673207 to your computer and use it in GitHub Desktop.
Remove protocol from URL
require 'uri'
url = 'http://google.com/'
def remove_protocol_from_url( url )
url = url[2..-1] if url.start_with?('//')
uri = URI(url)
if scheme = uri.scheme
url = url[scheme.length + 3..-1] # :// is 3 bytes
end
url
end
puts remove_protocol_from_url(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment