Object
Resolv::Hosts is a hostname resolver that uses the system hosts file.
Creates a new Resolv::Hosts, using
filename for its data source.
# File resolv.rb, line 178
def initialize(filename = DefaultFileName)
@filename = filename
@mutex = Mutex.new
@initialized = nil
end
Iterates over all IP addresses for name retrieved from the
hosts file.
# File resolv.rb, line 235
def each_address(name, &proc)
lazy_initialize
if @name2addr.include?(name)
@name2addr[name].each(&proc)
end
end
Iterates over all hostnames for address retrieved from the
hosts file.
# File resolv.rb, line 262
def each_name(address, &proc)
lazy_initialize
if @addr2name.include?(address)
@addr2name[address].each(&proc)
end
end
Gets the IP address of name from the hosts file.
# File resolv.rb, line 218
def getaddress(name)
each_address(name) {|address| return address}
raise ResolvError.new("#{@filename} has no name: #{name}")
end
Gets all IP addresses for name from the hosts file.
# File resolv.rb, line 226
def getaddresses(name)
ret = []
each_address(name) {|address| ret << address}
return ret
end
Commenting is here to help enhance the documentation. For example, sample code, or clarification of the documentation.
If you are posting code samples in your comments, please wrap them in "<pre><code class="ruby" > ... </code></pre>" markup in order to get syntax highlighting.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file a bug report so that it can be corrected for the next release. Thank you.