Skip to content

Commit

Permalink
Add new "Identity Comparison" rule
Browse files Browse the repository at this point in the history
This PR adds new "Equal Object Identifier" rule that prefers `equal?` over `==`
when comparing `object_id`. `Object#equal?` method is provided to compare objects
for identity, and comparing objects for equality using `Object#==` does not require
redundant `object_id` to be repeated.

```ruby
# bad
foo.object_id == bar.object_id

# good
foo.equal?(bar)
```
  • Loading branch information
koic authored and bbatsov committed Aug 8, 2020
1 parent 249d53f commit fb6ca99
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,19 @@ something = something && something.downcase
something &&= something.downcase
----

=== Identity Comparison [[identity-comparison]]

Prefer `equal?` over `==` when comparing `object_id`. `Object#equal?` is provided to compare objects for identity, and in contrast `Object#==` is provided for the purpose of doing value comparison.

[source,ruby]
----
# bad
foo.object_id == bar.object_id
# good
foo.equal?(bar)
----

=== Explicit Use of the Case Equality Operator [[no-case-equality]]

Avoid explicit use of the case equality operator `===`.
Expand Down

0 comments on commit fb6ca99

Please sign in to comment.