diff options
author | Marco Ceresa <bluemonk@users.noreply.github.com> | 2022-01-08 11:14:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-08 11:14:52 +0100 |
commit | 8ff186bd8d71da69fa33b999ff69be9d8885c424 (patch) | |
tree | 16941b3027ef5a805e86347806b75be61510109e | |
parent | 85b95efd1846958e13f4dd6225afffe5b39db306 (diff) | |
parent | 9b8d8fdd6489472349843d4607f8be8e05024857 (diff) | |
download | ipaddress-8ff186bd8d71da69fa33b999ff69be9d8885c424.tar.gz |
Merge pull request #77 from smortex/eql
Make eql? behare like ==.
-rw-r--r-- | lib/ipaddress/ipv4.rb | 1 | ||||
-rw-r--r-- | lib/ipaddress/ipv6.rb | 1 | ||||
-rw-r--r-- | test/ipaddress/ipv4_test.rb | 2 | ||||
-rw-r--r-- | test/ipaddress/ipv6_test.rb | 5 |
4 files changed, 9 insertions, 0 deletions
diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb index 70d1a51..82546d6 100644 --- a/lib/ipaddress/ipv4.rb +++ b/lib/ipaddress/ipv4.rb @@ -515,6 +515,7 @@ module IPAddress; return prefix <=> oth.prefix if to_u32 == oth.to_u32 to_u32 <=> oth.to_u32 end + alias eql? == # # Returns the number of IP addresses included diff --git a/lib/ipaddress/ipv6.rb b/lib/ipaddress/ipv6.rb index f427954..1601a01 100644 --- a/lib/ipaddress/ipv6.rb +++ b/lib/ipaddress/ipv6.rb @@ -528,6 +528,7 @@ module IPAddress; return prefix <=> oth.prefix if to_u128 == oth.to_u128 to_u128 <=> oth.to_u128 end + alias eql? == # # Returns the address portion of an IP in binary format, diff --git a/test/ipaddress/ipv4_test.rb b/test/ipaddress/ipv4_test.rb index 19e0450..5e8d5a9 100644 --- a/test/ipaddress/ipv4_test.rb +++ b/test/ipaddress/ipv4_test.rb @@ -387,8 +387,10 @@ class IPv4Test < Minitest::Test assert_equal false, ip3 < ip1 # ip1 should be equal to itself assert_equal true, ip1 == ip1 + assert_equal true, ip1.eql?(ip1) # ip1 should be equal to ip4 assert_equal true, ip1 == ip4 + assert_equal true, ip1.eql?(ip4) # test sorting arr = ["10.1.1.1/8","10.1.1.1/16","172.16.1.1/14"] assert_equal arr, [ip1,ip2,ip3].sort.map{|s| s.to_string} diff --git a/test/ipaddress/ipv6_test.rb b/test/ipaddress/ipv6_test.rb index 9d7736d..294d5fa 100644 --- a/test/ipaddress/ipv6_test.rb +++ b/test/ipaddress/ipv6_test.rb @@ -325,6 +325,11 @@ class IPv6Test < Minitest::Test assert_equal false, ip3 < ip1 # ip1 should be equal to itself assert_equal true, ip1 == ip1 + assert_equal true, ip1.eql?(ip1) + # ip1 should be equal to a copy of itself + other = ip1.dup + assert_equal true, ip1 == other + assert_equal true, ip1.eql?(other) # ip4 should be greater than ip1 assert_equal true, ip1 < ip4 assert_equal false, ip1 > ip4 |