The abs() is an inbuilt function in Ruby returns the absolute value of rational.
Syntax: rational.abs()
Parameters: The function accepts no parameter
Return Value: It returns returns the absolute value of rational.
Example 1:
# Ruby program for abs() method # Initialize rational number rat1 = Rational(-3, 4) # Prints the rational number puts rat1.abs() |
chevron_right
filter_none
Output:
3/4
Example 2:
# Ruby program for abs() method # Initialize rational number rat1 = Rational(-4) # Prints the rational number puts rat1.abs() |
chevron_right
filter_none
Output:
4/1
Recommended Posts:
- Ruby | Rational rational() function()
- Ruby Integer abs() function with example
- Ruby | Complex abs function
- Ruby | Numeric abs() function
- Ruby | Rational inspect() function
- Ruby | Rational numerator() function
- Ruby | Rational <=> function
- Ruby | Rational truncate() function
- Ruby | Rational to_s() function
- Ruby | Rational to_r() function
- Ruby | Rational to_i() function
- Ruby | Rational to_f() function
- Ruby | Rational ceil() function
- Ruby | Rational denominator() function
- Ruby | Rational fdiv() function
- Ruby | Rational floor() function
- Ruby | Rational quo() function
- Ruby | Rational negative?() function
- Ruby | Rational positive?() function
- Ruby | Rational round() 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.

