Я использую Ruby on Rails 3.0.10 и хотел бы получить часть scheme://domain универсального URL (примечание: синтаксис URL также может быть scheme://domain:port/path?query_string#fragment_id).
scheme://domain
scheme://domain:port/path?query_string#fragment_id
То есть, например, если у меня есть следующие URL-адреса
http://stackoverflow.com/questions/7304043/how-to-retrieve-the-scheme-domainport-part-of-a-generic-url ftp://some_link.org/some_other_string # Consider also 'https', 'ftps' and so on... 'scheme:' values.
Я бы хотел получить только части
# Note: The last '/' character was removed. http://stackoverflow.com ftp://some_link.org # Consider also 'https', 'ftps' and so on... 'scheme:' values.
. Как я могу это сделать?
require 'uri' uri = URI.parse("/4258287/kak-izvlech-chast-shemy-domen-obschego-url") url = "#{uri.scheme}://#{uri.host}" #url would be set to http://stackoverflow.com
С Модуль: URI .