首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Resolv::DNS::Name

Parent:Object

DNS 名称的表示。

公共类方法

创建(arg)显示源

从中创建一个新的 DNS 名称argarg可以是:

Name (名称)

返回arg

字符串

创建一个新的名称。

代码语言:javascript
复制
# File lib/resolv.rb, line 1212
def self.create(arg)
  case arg
  when Name
    return arg
  when String
    return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
  else
    raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")
  end
end

公共实例方法

absolute?() 显示源代码

如果此名称是绝对的,则为真。

代码语言:javascript
复制
# File lib/resolv.rb, line 1243
def absolute?
  return @absolute
end

subdomain_of?(other)显示源文件

如果other是子域,则返回 true 。

示例:

代码语言:javascript
复制
domain = Resolv::DNS::Name.create("y.z")
p Resolv::DNS::Name.create("w.x.y.z").subdomain_of?(domain) #=> true
p Resolv::DNS::Name.create("x.y.z").subdomain_of?(domain) #=> true
p Resolv::DNS::Name.create("y.z").subdomain_of?(domain) #=> false
p Resolv::DNS::Name.create("z").subdomain_of?(domain) #=> false
p Resolv::DNS::Name.create("x.y.z.").subdomain_of?(domain) #=> false
p Resolv::DNS::Name.create("w.z").subdomain_of?(domain) #=> false
代码语言:javascript
复制
# File lib/resolv.rb, line 1269
def subdomain_of?(other)
  raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other
  return false if @absolute != other.absolute?
  other_len = other.length
  return false if @labels.length <= other_len
  return @labels[-other_len, other_len] == other.to_a
end

to_s()显示源文件

以字符串形式返回域名。

即使名称对象是绝对的,域名也没有尾部点。

示例:

代码语言:javascript
复制
p Resolv::DNS::Name.create("x.y.z.").to_s #=> "x.y.z"
p Resolv::DNS::Name.create("x.y.z").to_s #=> "x.y.z"
代码语言:javascript
复制
# File lib/resolv.rb, line 1304
def to_s
  return @labels.join('.')
end

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com