aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-05 13:53:38 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-05 13:53:38 +0000
commitd0da57ac40bafaad95e90a375216ba1d9a658747 (patch)
tree050e10063c3ceff4fecaeaec4c333fe497e4d6cb /lib
parent3fd5f483c19eb3109cead3be412f23bf6a44f36c (diff)
downloadruby-d0da57ac40bafaad95e90a375216ba1d9a658747.tar.gz
IPAddr#== and IPAddr#<=> no longer raise an exception if coercion fails
* lib/ipaddr.rb (IPAddr#==): If coercion fails, return false instead of passing through the exception. [ruby-core:77451] [Bug #12799] * lib/ipaddr.rb (IPAddr#<=>): If coercion fails, return nil instead of passing through the exception. [ruby-core:77451] [Bug #12799] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/ipaddr.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb
index 458be58577..6f70ebf773 100644
--- a/lib/ipaddr.rb
+++ b/lib/ipaddr.rb
@@ -149,7 +149,10 @@ class IPAddr
# Returns true if two ipaddrs are equal.
def ==(other)
other = coerce_other(other)
- return @family == other.family && @addr == other.to_i
+ rescue
+ false
+ else
+ @family == other.family && @addr == other.to_i
end
# Returns a new ipaddr built by masking IP address with the given
@@ -335,10 +338,10 @@ class IPAddr
# Compares the ipaddr with another.
def <=>(other)
other = coerce_other(other)
-
- return nil if other.family != @family
-
- return @addr <=> other.to_i
+ rescue
+ nil
+ else
+ @addr <=> other.to_i if other.family == @family
end
include Comparable