Ruby | Rational rational() function()
Last Updated :
19 Mar, 2024
The Rational() is an inbuilt method in Ruby returns the rational number of the form a/b.
Syntax: Rational(num, den)
Parameters: The function accepts two parameters which represents numerator and denominator. By default, the denominator is 1.
Return Value: It returns the rational number of the form a/b.
Example 1:
rat = Rational( 4 )
puts rat
|
Output:
4/1
Example 2:
rat = Rational( 4 , 5 )
puts rat
|
Output:
4/5
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...