Ruby | Integer <=> function Last Updated : 19 Mar, 2024 Comments Improve Suggest changes Like Article Like Report The <=> is an inbuilt method in Ruby returns three values -1, 0 or +1. It returns -1 if the number is less than the given number, 0 if both are same, 1 if it is greater than the given number. Syntax: num1 <=> num2 Parameters: The function accepts no parameter. Return Value: It returns -1, 0, +1 as stated above. Example 1: Ruby # Ruby program for <=> method in Integer # Initialize numbers num1 = 6 num2 = 3 # Prints <=> print num1 <=> num2 Output: 1 Example 2: Ruby # Ruby program for <=> method in Integer # Initialize numbers num1 = 2 num2 = 3 # Prints <=> print num1 <=> num2 Output: -1 Example 3: Ruby # Ruby program for <=> method in Integer # Initialize numbers num1 = 3 num2 = 3 # Prints <=> print num1 <=> num2 Output: 0 Comment More infoAdvertise with us Next Article Ruby | Integer <=> function gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Integer-class Similar Reads Ruby | Integer >= function The >= is an inbuilt method in Ruby returns true if the number is greater than or equal to the given number, else it returns false. Syntax: num1 >= num2 Parameters: The function accepts no parameter. Return Value: It returns true if the number is greater than or equal to the given number, else 1 min read Ruby | Integer << function The << is an inbuilt method in Ruby returns the number which is shifted N times to the left. The resultant number is num * (2^N). Syntax: num << N Parameters: The function accepts no parameter. Return Value: It returns num * (2^N). Example 1: Ruby # Ruby program for << method in In 1 min read Ruby | Integer - function The - is an inbuilt method in Ruby returns the subtraction of two numbers. It returns num1 - num2. Syntax: num1 - num2 Parameters: The function accepts no parameter. Return Value: It returns the subtraction of two numbers. Example 1: Ruby # Ruby program for - method in Integer # Initialize numbers n 1 min read Ruby | Numeric integer() function The integer?() is an inbuilt method in Ruby returns a boolean value. It returns true if the number is an integer one, else it returns false. Syntax: num.integer?() Parameters: The function needs a number which is to be checked for. Return Value: It returns returns a boolean value. Example 1: CPP # R 1 min read Ruby | Integer upto() function The upto function in Ruby returns all the numbers from a given to number itself. It iterates the given block, passing in increasing values from number1 up to number2. If no block is given, an Enumerator is returned instead. Syntax: (number1).upto(number2) Parameter: The function takes number1 and nu 2 min read Ruby | Integer sqrt() function The sqrt() function in Ruby returns the integer square root of the non-negative integer n, i.e. the largest non-negative integer less than or equal to the square root of n Syntax: Integer.sqrt(number) Parameter: The function takes the integer whose square root is to be returned. It throws an error " 1 min read Ruby | Rational <=> function The <=> is an inbuilt method in Ruby returns -1, 0, or +1 depending on whether rational is less than, equal to, or greater than the numeric value. nil is returned if the two values are incomparable. Syntax: rat1<=>rat2 Parameters: The function accepts no parameter Return Value: It return 1 min read Ruby | Integer >> method The >> is an inbuilt method in Ruby returns the number which is shifted N times to the right. The resultant number is int(num / (2^N)). Syntax: num >> N Parameters: The function accepts no parameter. Return Value: It returns int(num / (2^N)). Example 1: Ruby # Ruby program for >> m 1 min read Ruby | Numeric real? function The real?() is an inbuilt method in Ruby returns a boolean value. It returns true if the number is a negative one, else it returns false. Syntax: num.real?() Parameters: The function needs a number which is to be checked for. Return Value: It returns returns a boolean value. Example 1: CPP # Ruby pr 1 min read Ruby | Numeric i() function The i() is an inbuilt method in Ruby returns a complex number with the imaginary part that is given. Syntax: num.i() Parameters: The function needs a number which is the imaginary part of the complex number. Return Value: It returns a complex number with the imaginary part. Example 1: CPP # Ruby pro 1 min read Like