Uh! Are you a cat?!

Object equality in Ruby

Mehdi Farsi
May 30 · 3 min read
  • The equal? method

eql? vs == vs ===

In Ruby, as any classes inherit directly (or not) from the Object class, then the object equality logic is implemented between the Kernel module and the BasicObject class.

The Kernel#=== method

This method is used to check equality in case statements.

The BasicObject#== method

This method is overridden in most of the Core classes in Ruby.

The Kernel#eql? method

This method tests object equality by checking if the 2 objects refer to the same hash key.

The equal? method

The BasicObject#equal? method is used to verify object identity.

ONE MORE THING ⬇

Feel free to subscribe here: www.rubycademy.com


rubycademy

E-Learning platform for Ruby and Ruby on Rails

Mehdi Farsi

Written by

Founder of www.rubycademy.com — I blog about Ruby & ROR - Paris

rubycademy

E-Learning platform for Ruby and Ruby on Rails