class Resolv::DNS::Name
Представление имени DNS.
Публичные Классовые Методы
Исходный код
# File lib/resolv.rb, line 1271
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 Создаёт новое имя DNS из arg. arg может быть:
Публичные Экземплярные Методы
Исходный код
# File lib/resolv.rb, line 1302 def absolute? return @absolute end
Истинно, если это имя абсолютное.
Исходный код
# File lib/resolv.rb, line 1328
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 Возвращает истину, если other является поддоменом.
Пример:
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
Исходный код
# File lib/resolv.rb, line 1363
def to_s
return @labels.join('.')
end Возвращает доменное имя в виде строки.
Доменное имя не имеет заключительной точки, даже если объект имени абсолютный.
Пример:
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"
Ruby Core © 1993–2024 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.