# File lib/mongo/address/ipv6.rb, line 50 def self.parse(address) # IPAddr's parser handles IP address only, not port. # Therefore we need to handle the port ourselves if address =~ /[\[\]]/ parts = address.match(/\A\[(.+)\](?::(\d+))?\z/) if parts.nil? raise ArgumentError, "Invalid IPv6 address: #{address}" end host = parts[1] port = (parts[2] || 27017).to_i else host = address port = 27017 end # Validate host. # This will raise IPAddr::InvalidAddressError # on newer rubies which is a subclass of ArgumentError # if host is invalid begin IPAddr.new(host) rescue ArgumentError raise ArgumentError, "Invalid IPv6 address: #{address}" end [ host, port ] end