红宝石 |理性检查()函数
inspect()是 Ruby 中的内置函数,将值作为字符串返回。
Syntax: rat.inspect()
Parameters: The function accepts no parameter
Return Value: It returns the value as a string
示例 1 :
# Ruby program for inspect() method
# Initialize rational number
rat1 = Rational(8, -6)
# Prints the rational number
puts rat1.inspect()
输出:
(-4/3)
示例 2 :
# Ruby program for inspect() method
# Initialize rational number
rat1 = Rational('1/2')
# Prints the rational number
puts rat1.inspect()
输出:
(1/2)