tags:

views:

974

answers:

1

I'm looking for a method to reliably extract the host name from a URL string in Ruby.

e.g. http://www.mglenn.com/directory = www.mglenn.com OR http://www.mglenn.com?param=x = www.mglenn.com

+19  A: 

You could try something like this:

require 'uri'

myUri = URI.parse( 'http://www.mglenn.com/directory' )
print myUri.host
glenatron