Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • resolv.rb



A representation of a DNS name.

Public Class Methods

create(arg) click to toggle source

Creates a new DNS name from arg. arg can be:


returns arg.


Creates a new Name.

               # File resolv.rb, line 1114
def self.create(arg)
  case arg
  when Name
    return arg
  when String
    return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
    raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")

Public Instance Methods

absolute?() click to toggle source

True if this name is absolute.

               # File resolv.rb, line 1137
def absolute?
  return @absolute
subdomain_of?(other) click to toggle source

Returns true if other is a subdomain.


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 resolv.rb, line 1162
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
to_s() click to toggle source

returns the domain name as a string.

The domain name doesn’t have a trailing dot even if the name object is absolute.


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"
               # File resolv.rb, line 1197
def to_s
  return @labels.join('.')

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.