Implementing Equality in Ruby - Shopify
May 26, 2022

Summary
This post details the nuances of implementing equality in Ruby, covering the `==`, `#eql?`, `#equal?`, and `#===` operators. It explains the distinction between entities (identified by an explicit `id`) and value objects (identified by their attributes), providing code examples for correct implementation of the `==` operator for both. It also discusses type coercion and the properties of a correct equality implementation (reflexivity, symmetry, transitivity), including the rare exception of NaN.