Parse a string; return an V4 instance if it’s a valid IPv4 address, nil otherwise
# File lib/ip/base.rb, line 273 def self.parse(str) if str =~ /\A(\d+)\.(\d+)\.(\d+)\.(\d+)(?:\/(\d+))?(?:@(.*))?\z/ pfxlen = ($5 || ADDR_BITS).to_i return nil if pfxlen > 32 addrs = [$1.to_i, $2.to_i, $3.to_i, $4.to_i] return nil if addrs.find { |n| n>255 } addr = (((((addrs[0] << 8) | addrs[1]) << 8) | addrs[2]) << 8) | addrs[3] new(addr, pfxlen, $6) end end
Generated with the Darkfish Rdoc Generator 2.