Ruby | Rational rationalize() function Last Updated : 19 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The rationalize() is an inbuilt function in Ruby returns a simpler approximation of the value if the optional argument eps is given (rat-|eps| <= result <= rat+|eps|) otherwise returns its self. Syntax: rat.rationalize(eps) Parameters: The function accepts a single optional parameter Return Value: It returns a simpler approximation of the value if the optional argument eps is given (rat-|eps| <= result <= rat+|eps|) otherwise returns its self Example 1: Ruby # Ruby program for rationalize() method # Initialize rational number rat1 = Rational(123, 456) # Prints the rational number puts rat1.rationalize Output: 41/152 Example 2: Ruby # Ruby program for rationalize() method # Initialize rational number rat1 = Rational(123, 456) # Prints the rational number puts rat1.rationalize(Rational('.001')) Output: 7/26 Comment More infoAdvertise with us Next Article Ruby | Rational rationalize() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Rational-class Similar Reads 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 round() function The round() is an inbuilt function in Ruby returns rational rounded to the nearest value with a precision of ndigits decimal digits. ndigits by default is 0. It returns a rational when ndigits is positive, otherwise returns an integer. Syntax: rational.round(ndigits) Parameters: The function accepts 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 <=> 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 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 Like