Resolv::Hosts is a hostname resolver that uses the system hosts file.

Methods
E
G
N
Constants
DefaultFileName = Win32::Resolv.get_hosts_path
 
Class Public methods
new(filename = DefaultFileName)

Creates a new Resolv::Hosts, using filename for its data source.

# File lib/resolv.rb, line 181
def initialize(filename = DefaultFileName)
  @filename = filename
  @mutex = Mutex.new
  @initialized = nil
end
Instance Public methods
each_address(name, &proc)

Iterates over all IP addresses for name retrieved from the hosts file.

# File lib/resolv.rb, line 238
def each_address(name, &proc)
  lazy_initialize
  if @name2addr.include?(name)
    @name2addr[name].each(&proc)
  end
end
each_name(address, &proc)

Iterates over all hostnames for address retrieved from the hosts file.

# File lib/resolv.rb, line 265
def each_name(address, &proc)
  lazy_initialize
  if @addr2name.include?(address)
    @addr2name[address].each(&proc)
  end
end
getaddress(name)

Gets the IP address of name from the hosts file.

# File lib/resolv.rb, line 221
def getaddress(name)
  each_address(name) {|address| return address}
  raise ResolvError.new("#{@filename} has no name: #{name}")
end
getaddresses(name)

Gets all IP addresses for name from the hosts file.

# File lib/resolv.rb, line 229
def getaddresses(name)
  ret = []
  each_address(name) {|address| ret << address}
  return ret
end
getname(address)

Gets the hostname of address from the hosts file.

# File lib/resolv.rb, line 248
def getname(address)
  each_name(address) {|name| return name}
  raise ResolvError.new("#{@filename} has no address: #{address}")
end
getnames(address)

Gets all hostnames for address from the hosts file.

# File lib/resolv.rb, line 256
def getnames(address)
  ret = []
  each_name(address) {|name| ret << name}
  return ret
end