Related Articles

Related Articles

Ruby | Rational rational() function()
  • Last Updated : 18 Dec, 2019

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for Rational()
  
# Initialize rational number 
rat = Rational(4)
  
# Prints the rational number
puts rat

chevron_right


Output:

4/1

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for Rational()
  
# Initialize rational number 
rat = Rational(4, 5)
  
# Prints the rational number
puts rat

chevron_right


Output:

4/5
My Personal Notes arrow_drop_up
Recommended Articles
Page :