Open In App

Ruby | Rational inspect() function

Improve
Improve
Like Article
Like
Save
Share
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 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)

Last Updated : 19 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads