Search code examples
rubyperlspaceship-operator

Why does the spaceship operator have only one equal sign in it?


Why was the spaceship operator <=> chosen to have one equal sign rather than two? Is this seen as inconsistent with one equal sign usually meaning assignment, and two meaning comparison?


Solution

  • Why would it have two? There's only one in <=, >= and !=. It's not inconsistent at all. Only == is inconsistent, and that's to avoid conflicts with the assignment operator.