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

parent 28ab1062
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment