📜  红宝石 |理性检查()函数

📅  最后修改于: 2022-05-13 01:54:57.559000             🧑  作者: Mango

红宝石 |理性检查()函数

inspect()是 Ruby 中的内置函数,将值作为字符串返回。

示例 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)