Ruby | Rational abs() function
Last Updated :
19 Mar, 2024
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:
rat1 = Rational(- 3 , 4 )
puts rat1.abs()
|
Output:
3/4
Example 2:
rat1 = Rational(- 4 )
puts rat1.abs()
|
Output:
4/1
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...