Open In App

Ruby | Rational inspect() function

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 program for inspect() method
  
# Initialize rational number
rat1 = Rational(8, -6)
  
# Prints the rational number
puts rat1.inspect()

Output:

(-4/3)

Example 2:




# Ruby program for inspect() method
  
# Initialize rational number
rat1 = Rational('1/2')
  
# Prints the rational number
puts rat1.inspect()

Output:

(1/2)
Article Tags :