Ruby | Rational inspect() function Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The inspect() is an inbuilt function in Ruby returns the value as a string. Syntax: rat.inspect() Parameters: The function accepts no parameter Return Value: It returns the value as a string Example 1: Ruby # Ruby program for inspect() method # Initialize rational number rat1 = Rational(8, -6) # Prints the rational number puts rat1.inspect() Output: (-4/3) Example 2: Ruby # Ruby program for inspect() method # Initialize rational number rat1 = Rational('1/2') # Prints the rational number puts rat1.inspect() Output: (1/2) Comment More infoAdvertise with us Next Article Ruby | Rational <=> function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Rational-class Similar Reads Ruby | Range inspect() function The inspect() is an inbuilt method in Ruby returns the range object in a printable form Syntax: range1.inspect() Parameters: The function accepts no parameter Return Value: It returns the range object in a printable form Example 1: Ruby # Ruby program for inspect() # method in Range # Initialize ran 1 min read Ruby | Rational negative?() function The negative?() is an inbuilt function in Ruby returns boolean value true if rational number is less than zero otherwise false. Syntax: rat.negative?() Parameters: The function accepts no parameter. Return Value: It returns boolean value true if rational number is less than zero otherwise return fal 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 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 <=> 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 Like