Skip to content

Instantly share code, notes, and snippets.

@jensendarren
Created January 8, 2015 12:48
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 jensendarren/708988610ecc3a98353f to your computer and use it in GitHub Desktop.
Save jensendarren/708988610ecc3a98353f to your computer and use it in GitHub Desktop.
An example of using URI in Ruby
require 'uri'
require 'open-uri'
google_url = "http://google.com/"
url = URI.parse(google_url)
# Get the hostname
puts "The hostname is #{url.hostname}"
# Get the path
puts "The path is #{url.path}"
# Split the url
puts URI.split(google_url).inspect
# Open a webpage
google_home = open(google_url).read
puts "Welcome to #{google_url} !!"
puts
puts google_home
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment