本文簡要介紹ruby語言中 URI::Generic.host
的用法。
用法
host [隻讀]
返回 URI
的主機組件。
URI("http://foo/bar/baz").host #=> "foo"
如果不存在主機組件,則返回 nil。
URI("mailto:foo@example.org").host #=> nil
該組件不包含端口號。
URI("http://foo:8080/bar/baz").host #=> "foo"
由於 IPv6 地址在 URI 中用括號括起來,因此此方法返回用括號括起來的 IPv6 地址。這種形式不適合傳遞給 TCPSocket.open
等套接字方法。如果需要解包的主機名,請使用 hostname
方法。
URI("http://[::1]/bar/baz").host #=> "[::1]"
URI("http://[::1]/bar/baz").hostname #=> "::1"
相關用法
- Ruby Generic.hostname用法及代碼示例
- Ruby Generic.hostname=用法及代碼示例
- Ruby Generic.host=用法及代碼示例
- Ruby Generic.hierarchical?用法及代碼示例
- Ruby Generic.query=用法及代碼示例
- Ruby Generic.normalize用法及代碼示例
- Ruby Generic.select用法及代碼示例
- Ruby Generic.fragment=用法及代碼示例
- Ruby Generic.path用法及代碼示例
- Ruby Generic.route_to用法及代碼示例
- Ruby Generic.merge!用法及代碼示例
- Ruby Generic.route_from用法及代碼示例
- Ruby Generic.merge用法及代碼示例
- Ruby Generic.query用法及代碼示例
- Ruby Generic.port用法及代碼示例
- Ruby Generic.password=用法及代碼示例
- Ruby Generic.fragment用法及代碼示例
- Ruby Generic.scheme用法及代碼示例
- Ruby Generic.scheme=用法及代碼示例
- Ruby Generic.coerce用法及代碼示例
- Ruby Generic.port=用法及代碼示例
- Ruby Generic.opaque用法及代碼示例
- Ruby Generic.path=用法及代碼示例
- Ruby Generic.user=用法及代碼示例
- Ruby Generator模塊用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Generic.host。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。