# Implementing Equality in Ruby

DevFeed: [Implementing Equality in Ruby](<https://devfeed.tech/articles/implementing-equality-in-ruby-1442.md>)

Original publisher: [Read original article](<https://shopify.engineering/implementing-equality-in-ruby>)

Author: Denis Defreyne

Published: 2022-05-26T14:00:01Z

Content type: tutorial

Language: en

Sources: [Shopify Engineering](<https://devfeed.tech/sources/shopify-engineering.md>), [Shopify Engineering - Shopify Engineering](<https://devfeed.tech/sources/shopify-engineering-shopify-engineering.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Domain-driven design (DDD)](<https://devfeed.tech/topics/domain-driven-design.md>), [Rails](<https://devfeed.tech/topics/rails.md>), [Object-relational mapping](<https://devfeed.tech/topics/orm.md>)

Tags: [ddd](<https://devfeed.tech/tags/ddd.md>), [identity](<https://devfeed.tech/tags/identity.md>), [model](<https://devfeed.tech/tags/model.md>), [models](<https://devfeed.tech/tags/models.md>), [orm](<https://devfeed.tech/tags/orm.md>), [programming](<https://devfeed.tech/tags/programming.md>), [ruby](<https://devfeed.tech/tags/ruby.md>)

## AI overview

This article explains how equality works in Ruby, including the roles of #==, #eql?, #equal?, and #===. It presents general implementation patterns for entities, whose identity is based on an explicit ID, and value objects, whose identity is determined by their complete value. It also relates these patterns to domain-driven design and Ruby on Rails ActiveRecord models.

## Source excerpt

Ruby is one of the few programming languages that get equality right. I often play around with other languages, but keep coming back to Ruby. This is because Ruby's implementation of equality is so nice. Let's walk through all forms of equality in Ruby and how to implement them.