Created
January 8, 2015 12:48
-
-
Save jensendarren/708988610ecc3a98353f to your computer and use it in GitHub Desktop.
An example of using URI in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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