Ruby | Numeric method
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
# Ruby program for <=> method in Numeric # Initialize two numbers a = 19 b = 4 # Prints 0 if equal else 1 puts a<=>b |
Output:
1
Example 2:
Ruby
# Ruby program for <=> method in Numeric # Initialize two numbers a = 13 b = 13 # Prints 0 if equal else 1 puts a <=> b |
Output:
0
Contact Us