diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb index 6b67d7e..02d2adc 100644 --- a/lib/ipaddr.rb +++ b/lib/ipaddr.rb @@ -164,6 +164,10 @@ def -(offset) # Returns true if two ipaddrs are equal. def ==(other) + if other.nil? + return false + end + other = coerce_other(other) rescue false diff --git a/test/test_ipaddr.rb b/test/test_ipaddr.rb index 4b7229f..b2c88ec 100644 --- a/test/test_ipaddr.rb +++ b/test/test_ipaddr.rb @@ -475,6 +475,8 @@ def test_equal assert_equal(false, @a != IPAddr.new("3ffe:505:2::")) assert_equal(false, @a == @inconvertible_range) assert_equal(false, @a == @inconvertible_string) + assert_equal(false, IPAddr.new("0.0.0.0") == nil) + assert_equal(false, IPAddr.new("::") == nil) end def test_compare