Comparing Idiomatic Spaceships in Ruby - hartley mcguire
05-Jul-2025 11
If you want to make a Ruby class comparable (ex. a > b), all you have to do is implement the "spaceship" method, <=>, and include the Comparable module. But how do you implement the spaceship?
If your class is simple, maybe a Die with 6 faces, you could just delegate to an attribute, like the Die's value1.
.
Comparing Idiomatic Spaceships in Ruby - hartley mcguire #ruby #rubydeveloper #rubyonrails #Comparing #Idiomatic #Spaceships #hartley #mcguire https://rubyonrails.ba/link/comparing-idiomatic-spaceships-in-ruby-hartley-mcguire