From: Sam Roberts Date: 2005-02-05T00:08:13+09:00 Subject: Re: 'example.com' == 'example.com.' => false... is this intended? Quoteing akr@m17n.org, on Fri, Feb 04, 2005 at 05:02:45PM +0900: > In article <20050204052951.GA2531@ensemble.local>, > Sam Roberts writes: > > > Why? When are they not the same? > > For example, if you have a machine named "museum", it is confusing with > "museum." domain. > > > They are equivalent in the DNS, Resolv::DNS#getaddress() would return > > the same A record for both. > > There are several top-domains which have A record: ac, museum, etc. > If your local domain have a machine named "ac", it is important to > distinguish a relative "ac" domain and the absolute "ac" domain. You only sometimes distinguish between the two, sometimes you convert them to each other: >> Name = Resolv::DNS::Name => Resolv::DNS::Name >> Name.create('museum') == Name.create('museum') => true # But, wouldn't this depend on the location? On my net, museum would # be museum.local. >> Name.create('museum') == Name.create('museum.') => false >> Name.create('museum').to_s == Name.create('museum.').to_s => true # Isn't it important to distinguish? n0=Resolv::DNS.new.getname("193.108.154.9") n1=Resolv.getname("193.108.154.9") => "a193-108-154-9.deploy.akamaitechnologies.com" # note it isn't absolute, though the DNS response was n0 == n1 => in `==': undefined method `absolute?' for "com":String (NoMethodError) # I have to change my String to a Name to compare it? Irritating. n1 = Resolv::DNS::Name.create(n0) n0 == n1 => false # DNS returns absolute names n2 = Resolv::DNS::Name.create(n0.to_s) n0 == n2 => false n0.to_s == n2.to_s => true Maybe you haven't seen how unuseful the behaviour of == is because you use it inside resolv.rb, and all names you see are absolute? Outside of resolv.rb (including input/output values of the common Resolv class methods) names are non-absolute strings, and the DNS Name objects can't be compared to them. > > Name doesn't have any comparison operators, so they occupy empty space. > > > > Do you have another idea on what Name < Name could mean? > > For example, lexical order. > > > I found it necessary to find whether a Name was a sub-domain of another. > > How would you recommend to do this, if there is no method? > > > > lhs.length > rhs.length && lhs.to_a[-rhs.length, rhs.length] == rhs.to_a > > > > is the best I came up with, and its not the kind of thing I would want > > to type regularly. > > Adding some method (not operator) is acceptable if it has a good name. The code I posted included the method #lt?, you could include it as is, or change its name. For consistency with #eql?, you may want to make it NOT convert its argument from String to Name, or you may want to change both to allow comparison to String. def lt?(name) n = Name.create(name) # maybe remove? length > n.length && to_a[-n.length, n.length] == n.to_a end def ==(other) other = Name.create(other) # maybe add? return @labels == other.to_a && @absolute == other.absolute? end alias eql? == Cheers, Sam