Class: Resolv::DNS::Name
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/resolv.rb |
Overview
A representation of a ::Resolv::DNS name.
Class Method Summary
-
.create(arg)
Creates a new
::Resolv::DNSname fromarg. - .new(labels, absolute = true) ⇒ Name constructor
Instance Attribute Summary
-
#absolute? ⇒ Boolean
readonly
True if this name is absolute.
Instance Method Summary
- #==(other) (also: #eql?)
- #[](i)
-
#eql?(other)
Alias for #==.
- #hash
- #inspect
- #length
-
#subdomain_of?(other) ⇒ Boolean
Returns true if
otheris a subdomain. - #to_a
-
#to_s
returns the domain name as a string.
Constructor Details
.new(labels, absolute = true) ⇒ Name
Class Method Details
.create(arg)
Creates a new ::Resolv::DNS name from arg. arg can be:
- Name
-
returns
arg. - String
-
Creates a new
Name.
Instance Attribute Details
#absolute? ⇒ Boolean (readonly)
True if this name is absolute.
# File 'lib/resolv.rb', line 1318
def absolute? return @absolute end
Instance Method Details
#==(other) Also known as: #eql?
[ GitHub ]#[](i)
[ GitHub ]# File 'lib/resolv.rb', line 1364
def [](i) # :nodoc: return @labels[i] end
#eql?(other)
Alias for #==.
# File 'lib/resolv.rb', line 1328
alias eql? == # :nodoc:
#hash
[ GitHub ]# File 'lib/resolv.rb', line 1352
def hash # :nodoc: return @labels.hash ^ @absolute.hash end
#inspect
[ GitHub ]# File 'lib/resolv.rb', line 1311
def inspect # :nodoc: "#<#{self.class}: #{self}#{@absolute ? '.' : ''}>" end
#length
[ GitHub ]# File 'lib/resolv.rb', line 1360
def length # :nodoc: return @labels.length end
#subdomain_of?(other) ⇒ Boolean
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 'lib/resolv.rb', line 1344
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_a
[ GitHub ]# File 'lib/resolv.rb', line 1356
def to_a # :nodoc: return @labels end
#to_s
# File 'lib/resolv.rb', line 1379
def to_s return @labels.join('.') end