Intro

I recently discovered a module that allows us to handle Uniform Resource Identifiers for Ruby, module URI.

Usage

We can extract the distinct parts of an assigned http address when using it.

It allows us to pass in a url as an argument, and extract the constituent parts (i.e. port, host, and scheme).

Example usage:

require 'uri'

uri = URI("http://foo.com/posts?id=30&limit=5#time=1305298413")
#=> #<URI::HTTP:0x00000000b14880
#URL:http://foo.com/posts?id=30&limit=5#time=1305298413>
uri.scheme
#=> "http"
uri.host
#=> "foo.com"
uri.path
#=> "/posts"
uri.query
#=> "id=30&limit=5"
uri.fragment
#=> "time=1305298413"
uri.to_s
#=> "http://foo.com/posts?id=30&limit=5#time=1305298413"