Skip to content
Related Articles

Related Articles

Ruby | Rational abs() function
  • Last Updated : 06 Jan, 2020

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()

Output:

3/4

Example 2:




# Ruby program for abs() method
  
# Initialize rational number 
rat1 = Rational(-4)
  
# Prints the rational number
puts rat1.abs()

Output:

4/1
My Personal Notes arrow_drop_up
Recommended Articles
Page :