protect NoMethodError from calling to_hash in ==/eql?; close #2002

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-04-04 10:54:46 +09:00
parent 28ab106292
commit b8ab6af39d
+10 -2
View File
@@ -12,7 +12,11 @@ class Hash
# ISO 15.2.13.4.1
def == (hash)
return true if self.equal?(hash)
hash = hash.to_hash
begin
hash = hash.to_hash
rescue NoMethodError
return false
end
return false if self.size != hash.size
self.each do |k,v|
return false unless hash.key?(k)
@@ -28,7 +32,11 @@ class Hash
# ISO 15.2.13.4.32 (x)
def eql?(hash)
return true if self.equal?(hash)
hash = hash.to_hash
begin
hash = hash.to_hash
rescue NoMethodError
return false
end
return false if self.size != hash.size
self.each do |k,v|
return false unless hash.key?(k)