Skip to content

Files

Latest commit

 

History

History
25 lines (17 loc) · 467 Bytes

Lint-HashCompareByIdentity.md

File metadata and controls

25 lines (17 loc) · 467 Bytes

Pattern: Use of object_id for key

Issue: -

Description

Prefer using Hash#compare_by_identity than using object_id for hash keys.

Examples

# bad
hash = {}
hash[foo.object_id] = :bar
hash.key?(baz.object_id)

# good
hash = {}.compare_by_identity
hash[foo] = :bar
hash.key?(baz)

Further Reading