mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
protect NoMethodError from calling to_hash in ==/eql?; close #2002
This commit is contained in:
+10
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user