Ruby | Rational to_r() function Last Updated : 19 Mar, 2024 Comments Improve Suggest changes Like Article Like Report The to_r() is an inbuilt function in Ruby returns it's own value Syntax: rat.to_r() Parameters: The function accepts no parameter Return Value: It returns it's own value Example 1: CPP #Ruby program for to_r() method #Initialize rational number rat1 = Rational(18, -4) #Prints the rational number puts rat1.to_r() Output: -9/2 Example 2: CPP #Ruby program for to_r() method #Initialize rational number rat1 = Rational(7) #Prints the rational number puts rat1.to_r() Output: 7/1 Comment More infoAdvertise with us Next Article Ruby | Rational to_r() function gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Rational-class Similar Reads Ruby | Rational to_i() function The to_i() is an inbuilt function in Ruby returns the truncated integer value Syntax: rat.to_i() Parameters: The function accepts no parameter Return Value: It returns the truncated integer value Example 1: CPP #Ruby program for to_i() method #Initialize rational number rat1 = Rational(9, -2) #Print 1 min read Ruby | Rational to_s() function The to_s() is an inbuilt function in Ruby returns value as string Syntax: rat.to_s() Parameters: The function accepts no parameter Return Value: It returns value as string Example 1: CPP #Ruby program for to_s() method #Initialize rational number rat1 = Rational(18, -4) #Prints the rational number p 1 min read Ruby | Rational to_f() function The to_f() is an inbuilt function in Ruby returns the float value Syntax: rat.to_f() Parameters: The function accepts no parameter Return Value: It returns the float value Example 1: CPP #Ruby program for to_f() method #Initialize rational number rat1 = Rational(9, -2) #Prints the rational number pu 1 min read Ruby | Rational quo() function The quo() is an inbuilt function in Ruby returns the rational number by performing division. Syntax: rat1.quo(rat2) Parameters: The function accepts a single parameter Return Value: It returns the rational number by performing division Example 1: Ruby # Ruby program for quo() method # Initialize rat 1 min read Ruby | Rational <=> function The <=> is an inbuilt method in Ruby returns -1, 0, or +1 depending on whether rational is less than, equal to, or greater than the numeric value. nil is returned if the two values are incomparable. Syntax: rat1<=>rat2 Parameters: The function accepts no parameter Return Value: It return 1 min read Ruby | Rational rational() function() 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 1 min read Ruby | Rational abs() function 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 # Ruby program for abs() method # Initialize rational number rat1 = R 1 min read Ruby | Rational truncate() function The truncate() is an inbuilt function in Ruby returns rat truncated (toward zero) to a precision of ndigits decimal digits. ndigits by default is 0. It returns a rational when ndigits is positive, otherwise returns an integer. Syntax: rat.truncate(ndigits) Parameters: The function accepts a single p 1 min read Ruby | Rational numerator() function The numerator() is an inbuilt function in Ruby returns the numerator. Syntax: rat.numerator() Parameters: The function accepts no parameter Return Value: It returns the numerator Example 1: Ruby # Ruby program for numerator() method # Initialize rational number rat1 = Rational(7, -3) # Prints the ra 1 min read Ruby | Rational fdiv() function The fdiv() is an inbuilt function in Ruby returns float by performing division. Syntax: rat.fdiv(numeric)Parameters: The function accepts a single parameterReturn Value: It returns float by performing division  Example 1:  Ruby # Ruby program for fdiv() method # Initialize rational number rat1 = 1 min read Like