Get the URI
defining the local dRuby space.
This is the URI
of the current server. See current_server
.
Get the URI
defining the local dRuby space.
This is the URI
of the current server. See current_server
.
Sets userinfo, argument is string like ‘name:pass’.
Returns the userinfo, either as ‘user’ or ‘user:password’.
Returns attributes.
Setter for attributes val
.
Allows the opening of various resources including URIs.
If the first argument responds to the ‘open’ method, ‘open’ is called on it with the rest of the arguments.
If the first argument is a string that begins with <code>(protocol)://<code>, it is parsed by URI.parse
. If the parsed object responds to the ‘open’ method, ‘open’ is called on it with the rest of the arguments.
Otherwise, Kernel#open
is called.
OpenURI::OpenRead#open
provides URI::HTTP#open
, URI::HTTPS#open
and URI::FTP#open
, Kernel#open
.
We can accept URIs and strings that begin with http://, https:// and ftp://. In these cases, the opened file object is extended by OpenURI::Meta
.
Construct a URI
instance, using the scheme to detect the appropriate class from URI.scheme_list
.
URI::split(uri)
Splits the string on following parts and returns array with result:
Scheme
Userinfo
Host
Port
Registry
Path
Opaque
Query
Fragment
require 'uri' URI.split("http://www.ruby-lang.org/") # => ["http", nil, "www.ruby-lang.org", nil, nil, "/", nil, nil, nil]
URI::parse(uri_str)
Creates one of the URI’s subclasses instance from the string.
URI::InvalidURIError
Raised if URI
given is not a correct one.
require 'uri' uri = URI.parse("http://www.ruby-lang.org/") # => #<URI::HTTP http://www.ruby-lang.org/> uri.scheme # => "http" uri.host # => "www.ruby-lang.org"
It’s recommended to first ::escape the provided uri_str
if there are any invalid URI
characters.
URI::join(str[, str, ...])
str
String(s) to work with, will be converted to RFC3986 URIs before merging.
Joins URIs.
require 'uri' URI.join("http://example.com/","main.rbx") # => #<URI::HTTP http://example.com/main.rbx> URI.join('http://example.com', 'foo') # => #<URI::HTTP http://example.com/foo> URI.join('http://example.com', '/foo', '/bar') # => #<URI::HTTP http://example.com/bar> URI.join('http://example.com', '/foo', 'bar') # => #<URI::HTTP http://example.com/bar> URI.join('http://example.com', '/foo/', 'bar') # => #<URI::HTTP http://example.com/foo/bar>
URI::extract(str[, schemes][,&blk])
Extracts URIs from a string. If block given, iterates through all matched URIs. Returns nil if block given or array with matches.
require "uri" URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.") # => ["http://foo.example.com/bla", "mailto:test@example.com"]
URI::regexp([match_schemes])
match_schemes
Array
of schemes. If given, resulting regexp matches to URIs whose scheme is one of the match_schemes.
Returns a Regexp
object which matches to URI-like strings. The Regexp
object returned by this method includes arbitrary number of capture group (parentheses). Never rely on its number.
require 'uri' # extract first URI from html_string html_string.slice(URI.regexp) # remove ftp URIs html_string.sub(URI.regexp(['ftp']), '') # You should not rely on the number of parentheses html_string.scan(URI.regexp) do |*matches| p $& end
Parse uri
into a [uri, option] pair.
The DRbProtocol
module asks each registered protocol in turn to try to parse the URI
. Each protocol signals that it does not handle that URI
by raising a DRbBadScheme
error. If no protocol recognises the URI
, then a DRbBadURI
error is raised.
Parse uri
into a [uri, option] pair.
The DRbProtocol
module asks each registered protocol in turn to try to parse the URI
. Each protocol signals that it does not handle that URI
by raising a DRbBadScheme
error. If no protocol recognises the URI
, then a DRbBadURI
error is raised.
The UriFormatter
handles URIs from user-input and escaping.
uf = Gem::UriFormatter.new 'example.com' p uf.normalize #=> 'http://example.com'
do nothing
Checks the user
and password
.
If password
is not provided, then user
is split, using URI::Generic.split_userinfo
, to pull user
and +password.
See also URI::Generic.check_user
, URI::Generic.check_password
.
Protected setter for the user
component, and password
if available (with validation).
See also URI::Generic.userinfo=
.