class RuboCop::Cop::Lint::HashCompareByIdentity
= :bar
hash = {}.compare_by_identity
# good<br><br>hash.key?(baz.object_id)<br>hash = :bar
hash = {}
# bad
@example
methods (‘key?`, etc.) is actually a hash.
Furthermore, this cop cannot guarantee that the receiver of one of the
could be a false positive.
ids and other values that need be compared by value, and thus
This cop is unsafe. Although unlikely, the hash could store both object
@safety
one of these methods: `key?`, `has_key?`, `fetch`, `[]` and `[]=`.
This cop looks for hashes being keyed by objects’ ‘object_id`, using
for hash keys.
Prefer using `Hash#compare_by_identity` rather than using `object_id`
def on_send(node)
def on_send(node) add_offense(node) if id_as_hash_key?(node) end