static public Method

URI.parse(uri)

Synopsis

URI::parse(uri_str)

Args

uri_str:String with URI.

Description

Creates one of the URI’s subclasses instance from the string.

Raises

URI::InvalidURIError

Raised if URI given is not a correct one.

Usage

require 'uri'

uri = URI.parse("http://www.ruby-lang.org/")
p uri
# => #<URI::HTTP:0x202281be URL:http://www.ruby-lang.org/>
p uri.scheme
# => "http"
p uri.host
# => "www.ruby-lang.org"

Source Code

# File uri/common.rb, line 483
def self.parse(uri)
  scheme, userinfo, host, port, 
    registry, path, opaque, query, fragment = self.split(uri)

  if scheme && @@schemes.include?(scheme.upcase)
    @@schemes[scheme.upcase].new(scheme, userinfo, host, port, 
                                 registry, path, opaque, query, 
                                 fragment)
  else
    Generic.new(scheme, userinfo, host, port, 
                registry, path, opaque, query, 
                fragment)
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.