Skip to content

Commit

Permalink
Add new "Equal Object Identifier" 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 committed Aug 8, 2020
1 parent 249d53f commit f0ee4b3
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
----

=== Equal Object Identifier [[equal-object-id]]

Prefer `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.

[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 f0ee4b3

Please sign in to comment.