Class: Gem::Resolv::DNS::Name
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubygems/vendor/resolv/lib/resolv.rb |
Overview
A representation of a ::Gem::Resolv::DNS
name.
Class Method Summary
-
.create(arg)
Creates a new
::Gem::Resolv::DNS
name fromarg
. - .new(labels, absolute = true) ⇒ Name constructor Internal use only
Instance Attribute Summary
-
#absolute? ⇒ Boolean
readonly
True if this name is absolute.
Instance Method Summary
-
#subdomain_of?(other) ⇒ Boolean
Returns true if
other
is a subdomain. -
#to_s
returns the domain name as a string.
- #==(other) (also: #eql?) Internal use only
- #[](i) Internal use only
-
#eql?(other)
Internal use only
Alias for #==.
- #hash Internal use only
- #inspect Internal use only
- #length Internal use only
- #to_a Internal use only
Constructor Details
.new(labels, absolute = true) ⇒ Name
This method is for internal use only.
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1266
def initialize(labels, absolute=true) # :nodoc: labels = labels.map {|label| case label when String then Label::Str.new(label) when Label::Str then label else raise ArgumentError, "unexpected label: #{label.inspect}" end } @labels = labels @absolute = absolute end
Class Method Details
.create(arg)
Creates a new ::Gem::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/rubygems/vendor/resolv/lib/resolv.rb', line 1286
def absolute? return @absolute end
Instance Method Details
#==(other) Also known as: #eql?
This method is for internal use only.
[ GitHub ]
#[](i)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1332
def [](i) # :nodoc: return @labels[i] end
#eql?(other)
This method is for internal use only.
Alias for #==.
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1296
alias eql? == # :nodoc:
#hash
This method is for internal use only.
[ GitHub ]
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1320
def hash # :nodoc: return @labels.hash ^ @absolute.hash end
#inspect
This method is for internal use only.
[ GitHub ]
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1279
def inspect # :nodoc: "#<#{self.class}: #{self}#{@absolute ? '.' : ''}>" end
#length
This method is for internal use only.
[ GitHub ]
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1328
def length # :nodoc: return @labels.length end
#subdomain_of?(other) ⇒ Boolean
Returns true if other
is a subdomain.
Example:
domain = Gem::Resolv::DNS::Name.create("y.z")
p Gem::Resolv::DNS::Name.create("w.x.y.z").subdomain_of?(domain) #=> true
p Gem::Resolv::DNS::Name.create("x.y.z").subdomain_of?(domain) #=> true
p Gem::Resolv::DNS::Name.create("y.z").subdomain_of?(domain) #=> false
p Gem::Resolv::DNS::Name.create("z").subdomain_of?(domain) #=> false
p Gem::Resolv::DNS::Name.create("x.y.z.").subdomain_of?(domain) #=> false
p Gem::Resolv::DNS::Name.create("w.z").subdomain_of?(domain) #=> false
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1312
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
This method is for internal use only.
[ GitHub ]
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1324
def to_a # :nodoc: return @labels end
#to_s
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1347
def to_s return @labels.join('.') end