Skip to content

Commit

Permalink
More consistent comparison with compare_by_identity
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Nov 7, 2019
1 parent 0e1abda commit 1dc88ec
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/hash.cr
Original file line number Diff line number Diff line change
Expand Up @@ -922,11 +922,19 @@ class Hash(K, V)

private def entry_matches?(entry, key)
entry_key = entry.key
if @compare_by_identity && entry_key.responds_to?(:object_id)
if key.responds_to?(:object_id)
entry_key.object_id == key.object_id
else

if @compare_by_identity
if entry_key.responds_to?(:object_id)
if key.responds_to?(:object_id)
entry_key.object_id == key.object_id
else
false
end
elsif key.responds_to?(:object_id)
# because entry_key doesn't respond to :object_id
false
else
entry_key == key
end
else
entry_key == key
Expand Down

0 comments on commit 1dc88ec

Please sign in to comment.