Ruby Spaceship <=> Operator
Adhering to the law of trichotomy, the <=> operator (sometimes called the “Spaceship Operator”) works by comparing two elements and returning a -1, 0, or 1. While the original mathematical criteria applies to only real numbers, many programming languages implement the law of trichotomy as a general comparison between equivalent types. Ruby’s <=> operator can be a bit confusing but when understood, is very powerful.
Post a comment