Open In App

Ruby | Numeric method

Last Updated : 19 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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


 


Next Article

Similar Reads