Project

General

Profile

Feature #11666 ยป patch.diff

Glass_saga (Masaki Matsushita), 11/08/2015 07:19 AM

View differences:

lib/ipaddr.rb
end
alias === include?
def private?
# RFC1918: Private Address Space
@@__private_network_class_a ||= self.class.new("10.0.0.0/8")
@@__private_network_class_b ||= self.class.new("172.16.0.0/12")
@@__private_network_class_c ||= self.class.new("192.168.0.0/16")
return true if @@__private_network_class_a.include?(self) || \
@@__private_network_class_b.include?(self) || \
@@__private_network_class_c.include?(self)
return false
end
# Returns the integer representation of the ipaddr.
def to_i
return @addr
test/test_ipaddr.rb
end
def test_private?
assert_equal(true, IPAddr.new("10.0.0.0").private?)
assert_equal(true, IPAddr.new("10.255.255.255").private?)
assert_equal(true, IPAddr.new("172.16.0.0").private?)
assert_equal(true, IPAddr.new("172.31.255.255").private?)
assert_equal(true, IPAddr.new("192.168.0.0").private?)
assert_equal(true, IPAddr.new("192.168.255.255").private?)
assert_equal(false, IPAddr.new("192.1.0.0").private?)
assert_equal(false, IPAddr.new("172.32.0.0").private?)
assert_equal(false, IPAddr.new("11.0.0.0").private?)
end
def test_hash
a1 = IPAddr.new('192.168.2.0')
a2 = IPAddr.new('192.168.2.0')
    (1-1/1)