Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the name of the <=> operator in Ruby? What do they call it?

In Ruby there is the <=> operator. In the API they do not name its name, just:

The class must define the <=> operator...

Comparable uses <=> to implement the conventional comparison...

...the objects in the collection must also implement a meaningful <=> operator...

What is its name?

like image 883
Green Avatar asked Feb 28 '13 14:02

Green


3 Answers

See @Tony's above. However, it's also called (in slang) the "spaceship operator".

like image 187
Linuxios Avatar answered Oct 06 '22 22:10

Linuxios


It's called the Combined Comparison Operator

Combined comparison operator. Returns 0 if first operand equals second, 1 if first operand is greater than the second and -1 if first operand is less than the second.

(a <=> b) returns -1.
like image 25
Tony The Lion Avatar answered Oct 06 '22 22:10

Tony The Lion


This is called the combined comparison operator. Returns 0 if first operand equals second, 1 if first operand is greater than the second and -1 if first operand is less than the second.

Source

like image 2
Intrepidd Avatar answered Oct 07 '22 00:10

Intrepidd