Skip to content

Commit

Permalink
Add "instance_of? vs class comparison" section
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima authored and bbatsov committed Oct 8, 2020
1 parent 801381a commit 59db77d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.adoc
Expand Up @@ -2280,6 +2280,21 @@ something.instance_of?(Array)
something.is_a?(Array)
----

=== `instance_of?` vs class comparison [[instance-of-vs-class-comparison]]

Use `Object#instance_of?` instead of class comparison for equality.

[source,ruby]
----
# bad
var.class == Date
var.class.equal?(Date)
var.class.eql?(Date)
var.class.name == 'Date'
# good
var.instance_of?(Date)
----

=== `==` vs `eql?` [[eql]]

Expand Down

0 comments on commit 59db77d

Please sign in to comment.