The <=> is an inbuilt method in Ruby, which returns 0 if both the numbers are equal, else it returns 1.
Syntax: a <=> b
Parameters: The function needs two number whose comparison is to be done.
Return Value: It returns 0 if both the numbers are same, else it returns 1.
Example 1:
# Ruby program for <=> method in Matrix # Initialize two numbers a = 19 b = 4 # Prints 0 if equal else 1 puts a<=>b |
chevron_right
filter_none
Output:
1
Example 2:
# Ruby program for <=> method in Matrix # Initialize two numbers a = 13 b = 13 # Prints 0 if equal else 1 puts a <=> b |
chevron_right
filter_none
Output:
0
Recommended Posts:
- Ruby | Numeric - method
- Ruby | Numeric + method
- Ruby | Numeric % method
- Ruby | Numeric imaginary() function
- Ruby | Numeric i() function
- Ruby | Numeric fdiv() function
- Ruby | Numeric zero? function
- Ruby | Numeric floor() function
- Ruby | Numeric phase() function
- Ruby | Numeric finite?() function
- Ruby | Numeric real? function
- Ruby | Numeric divmod() function
- Ruby | Numeric div() function
- Ruby | Numeric denominator() function
- Ruby | Numeric conjugate() function
- Ruby | Numeric conj() function
- Ruby | Numeric coerce() function
- Ruby | Numeric arg() function
- Ruby | Numeric angle() function
- Ruby | Numeric abs2() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

