The abs() function in Ruby returns the absolute value of the integer.
Syntax: (number).abs
Parameter: The function takes the integer whose absolute value is to be returned.
Return Value: The function returns the absolute value of the integer.
Example #1:
# Ruby program Integer abs() function # Initializing the numbers num1 = -21num2 = 21 num3 = 0 num4 = -100 # Printing the absolute value of integers puts (num1).abs puts (num2).abs puts (num3).abs puts (num4).abs |
chevron_right
filter_none
Output :
21 21 0 100
Example #2:
# Ruby program of Integer abs() function # Initializing the numbers num1 =29num2 = -7num3 = 90num4 = -10 # Printing the absolute value of integers puts (num1).abs puts (num2).abs puts (num3).abs puts (num4).abs |
chevron_right
filter_none
Output:
29 7 90 10
Recommended Posts:
- Ruby Integer integer? function with example
- Ruby | Complex abs function
- Ruby | Numeric abs() function
- Ruby | Rational abs() function
- Ruby Integer odd? function with example
- Ruby Integer div() function with example
- Ruby Integer pred() function with example
- Ruby Integer bit_length function with example
- Ruby Integer ceil function with example
- Ruby Integer chr function with example
- Ruby Integer digits function with example
- Ruby Integer downto() function with example
- Ruby Integer divmod() function with example
- Ruby Integer even? function with example
- Ruby Integer fdiv() function with example
- Ruby Integer floor() function with example
- Ruby Integer gcd() function with example
- Ruby Integer gcdlcm() function with example
- Ruby Integer lcm() function with example
- Ruby Integer magnitude function with example
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.

