summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFrancis Luong (Franco) <franco@definefunk.com>2017-08-30 07:46:53 -0400
committerGitHub <noreply@github.com>2017-08-30 07:46:53 -0400
commit9dedeaf13caddb1827a48091c353c8f953b517ac (patch)
treef4347c4d451e147661ea01d93aebc6eac6b053ff /lib
parent032e8247f7840a490b226d6fbee89b4799b88660 (diff)
parente5c9039420d0d38e066aa2f81c46cba698d7803a (diff)
downloadipaddress-9dedeaf13caddb1827a48091c353c8f953b517ac.tar.gz
Merge pull request #76 from smortex/spaceship_compare
Fix <=> for IPv4 and IPv6.
Diffstat (limited to 'lib')
-rw-r--r--lib/ipaddress/ipv4.rb1
-rw-r--r--lib/ipaddress/ipv6.rb1
2 files changed, 2 insertions, 0 deletions
diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb
index a123e71..5979489 100644
--- a/lib/ipaddress/ipv4.rb
+++ b/lib/ipaddress/ipv4.rb
@@ -509,6 +509,7 @@ module IPAddress;
# #=> ["10.100.100.1/8","10.100.100.1/16","172.16.0.1/16"]
#
def <=>(oth)
+ return nil unless oth.is_a?(self.class)
return prefix <=> oth.prefix if to_u32 == oth.to_u32
to_u32 <=> oth.to_u32
end
diff --git a/lib/ipaddress/ipv6.rb b/lib/ipaddress/ipv6.rb
index 6ae651d..2205de4 100644
--- a/lib/ipaddress/ipv6.rb
+++ b/lib/ipaddress/ipv6.rb
@@ -494,6 +494,7 @@ module IPAddress;
# #=> ["2001:db8:1::1/64","2001:db8:1::1/65","2001:db8:2::1/64"]
#
def <=>(oth)
+ return nil unless oth.is_a?(self.class)
return prefix <=> oth.prefix if to_u128 == oth.to_u128
to_u128 <=> oth.to_u128
end