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

4

5

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?

Piscatorial answered 28/2, 2013 at 14:28 Comment(0)
Z
5

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

Zig answered 28/2, 2013 at 14:30 Comment(0)
E
4

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.
Evermore answered 28/2, 2013 at 14:30 Comment(5)
That's what it's called, but nobody calls it that.Terina
@JörgWMittag: We call it the "spaceship"!Zig
@Zig We’re more addicted to real life, so we call it “nunchaku”. But “spaceship” will be my fave from now on.Brunella
@mudasobwa: Who's "we" in this case?Zig
@Zig We with colleagues.Brunella
W
2

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

Wriggle answered 28/2, 2013 at 14:31 Comment(0)
G
1

Ive also heard it just called the double hash rocket

Garnettgarnette answered 10/9, 2013 at 4:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.