Skip to content

Instantly share code, notes, and snippets.

@atomical
Created January 28, 2014 18:22
Show Gist options
  • Select an option

  • Save atomical/8673207 to your computer and use it in GitHub Desktop.

Select an option

Save atomical/8673207 to your computer and use it in GitHub Desktop.

Revisions

  1. atomical created this gist Jan 28, 2014.
    16 changes: 16 additions & 0 deletions remove_protocol_from_url.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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)