class Gem::Resolv::IPv4

def self.create(arg)

def self.create(arg)
  case arg
  when IPv4
    return arg
  when Regex
    if (0..255) === (a = $1.to_i) &&
       (0..255) === (b = $2.to_i) &&
       (0..255) === (c = $3.to_i) &&
       (0..255) === (d = $4.to_i)
      return self.new([a, b, c, d].pack("CCCC"))
    else
      raise ArgumentError.new("IPv4 address with invalid value: " + arg)
    end
  else
    raise ArgumentError.new("cannot interpret as IPv4 address: #{arg.inspect}")
  end
end

def ==(other) # :nodoc:

:nodoc:
def ==(other) # :nodoc:
  return @address == other.address
end

def eql?(other) # :nodoc:

:nodoc:
def eql?(other) # :nodoc:
  return self == other
end

def hash # :nodoc:

:nodoc:
def hash # :nodoc:
  return @address.hash
end

def initialize(address) # :nodoc:

:nodoc:
def initialize(address) # :nodoc:
  unless address.kind_of?(String)
    raise ArgumentError, 'IPv4 address must be a string'
  end
  unless address.length == 4
    raise ArgumentError, "IPv4 address expects 4 bytes but #{address.length} bytes"
  end
  @address = address
end

def inspect # :nodoc:

:nodoc:
def inspect # :nodoc:
  return "#<#{self.class} #{self}>"
end

def to_name

def to_name
  return DNS::Name.create(
    '%d.%d.%d.%d.in-addr.arpa.' % @address.unpack('CCCC').reverse)
end

def to_s # :nodoc:

:nodoc:
def to_s # :nodoc:
  return sprintf("%d.%d.%d.%d", *@address.unpack("CCCC"))
end