mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/resolv.rb (Resolv::DNS::Name#subdomain_of?): new method.
(Resolv::DNS::Name#inspect): ditto. Suggested by Sam Roberts. [ruby-talk:129086] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b8f04a8bcb
commit
9bdb4b4b08
2 changed files with 37 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Tue Feb 8 00:19:02 2005 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
* lib/resolv.rb (Resolv::DNS::Name#subdomain_of?): new method.
|
||||||
|
(Resolv::DNS::Name#inspect): ditto.
|
||||||
|
Suggested by Sam Roberts. [ruby-talk:129086]
|
||||||
|
|
||||||
Mon Feb 7 23:14:11 2005 Tanaka Akira <akr@m17n.org>
|
Mon Feb 7 23:14:11 2005 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
* io.c (io_getc): flush rb_stdout before read fro stdin, which is
|
* io.c (io_getc): flush rb_stdout before read fro stdin, which is
|
||||||
|
|
|
@ -978,15 +978,38 @@ class Resolv
|
||||||
@absolute = absolute
|
@absolute = absolute
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
"#<#{self.class}: #{self.to_s}#{@absolute ? '.' : ''}>"
|
||||||
|
end
|
||||||
|
|
||||||
def absolute?
|
def absolute?
|
||||||
return @absolute
|
return @absolute
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
|
return false unless Name === other
|
||||||
return @labels == other.to_a && @absolute == other.absolute?
|
return @labels == other.to_a && @absolute == other.absolute?
|
||||||
end
|
end
|
||||||
alias eql? ==
|
alias eql? ==
|
||||||
|
|
||||||
|
# tests subdomain-of relation.
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
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
|
||||||
|
|
||||||
def hash
|
def hash
|
||||||
return @labels.hash ^ @absolute.hash
|
return @labels.hash ^ @absolute.hash
|
||||||
end
|
end
|
||||||
|
@ -1003,6 +1026,14 @@ class Resolv
|
||||||
return @labels[i]
|
return @labels[i]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
#
|
||||||
def to_s
|
def to_s
|
||||||
return @labels.join('.')
|
return @labels.join('.')
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue