This blog is part of our Ruby 2.4 series.
is used to check whether two IP addresses are equal or not.
Ruby also has
which is used to compare two IP addresses.
In Ruby 2.3, behavior of these methods was inconsistent.
Let’s see an example.
But if the first argument is invalid IP address
and second is valid IP address,
then it would return
<=> method would raise exception in both the cases.
In Ruby 2.4,
for both the methods
to return the result without raising exception,
if the objects being compared can’t be converted to an IPAddr object.
This might cause some backward compatibility
if our code is expecting the exception
which is no longer raised in Ruby 2.4.