What is the Ruby <=> (spaceship) operator? Is the operator implemented by any other languages?
What is the Ruby <=> (spaceship) operator? Is the operator implemented by any other
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The spaceship operator will return
1,0, or−1depending on the value of the left argument relative to the right argument.It’s commonly used for sorting data.
It’s also known as the Three-Way Comparison Operator. Perl was likely the first language to use it. Some other languages that support it are Apache Groovy, PHP 7+, and C++20.