Class: Resolv::DNS::Name (Ruby 2.3.7)
Description: Class : Resolv::DNS::Name - Ruby 2.3.7

- Home
- Core 2.3.7
- Std-lib 2.3.7
- Downloads

Support for the Ruby 2.3 series has ended. See here for reference.

### Home Classes Methods

### In Files

- resolv.rb

### Parent

Object

### Methods

- ::create
- #absolute?
- #subdomain_of?
- #to_s

### Class/Module Index

Quicksearch

- Resolv
- Resolv::DNS
- Resolv::DNS::Config
- Resolv::DNS::Config::NXDomain
- Resolv::DNS::Config::OtherResolvError
- Resolv::DNS::DecodeError
- Resolv::DNS::EncodeError
- Resolv::DNS::Name
- Resolv::DNS::Query
- Resolv::DNS::Requester
- Resolv::DNS::Requester::RequestError
- Resolv::DNS::Resource
- Resolv::DNS::Resource::ANY
- Resolv::DNS::Resource::CNAME
- Resolv::DNS::Resource::DomainName
- Resolv::DNS::Resource::Generic
- Resolv::DNS::Resource::HINFO
- Resolv::DNS::Resource::IN
- Resolv::DNS::Resource::IN::A
- Resolv::DNS::Resource::IN::AAAA
- Resolv::DNS::Resource::IN::SRV
- Resolv::DNS::Resource::IN::WKS
- Resolv::DNS::Resource::LOC
- Resolv::DNS::Resource::MINFO
- Resolv::DNS::Resource::MX
- Resolv::DNS::Resource::NS
- Resolv::DNS::Resource::PTR
- Resolv::DNS::Resource::SOA
- Resolv::DNS::Resource::TXT
- Resolv::Hosts
- Resolv::IPv4
- Resolv::IPv6
- Resolv::LOC
- Resolv::LOC::Alt
- Resolv::LOC::Coord
- Resolv::LOC::Size
- Resolv::MDNS
- Resolv::ResolvError
- Resolv::ResolvTimeout

No matching classes.

# Resolv::DNS::Name

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:

Name

  returns `arg`.

String

  Creates a new Name.

                   # File resolv.rb, line 1254
    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

### Public Instance Methods

absolute?() click to toggle source

True if this name is absolute.

                   # File resolv.rb, line 1285
    def absolute?
      return @absolute
    end

subdomain_of?(other) click to toggle source

Returns true if `other` is a subdomain.

Example:

    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 1311
    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() 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.

Example:

    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 1346
    def to_s
      return @labels.join('.')
    end