Horje
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)



Reffered: https://www.geeksforgeeks.org


Ruby

Related
Ruby | Numeric truncate() function Ruby | Numeric truncate() function
Ruby | Rational floor() function Ruby | Rational floor() function
Ruby | Numeric to_int() function Ruby | Numeric to_int() function
Ruby | Rational fdiv() function Ruby | Rational fdiv() function
Ruby | Numeric to_c() function Ruby | Numeric to_c() function

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
7