红宝石 |数值 real()函数
real()是 Ruby 中的一个内置方法,返回给定数字的实部。
Syntax: num.real()
Parameters: The function needs the number whose real part is to be returned.
Return Value: It returns the real part of the complex number.
示例 1 :
# Ruby program for real()
# method in Numeric
# Initialize a number
num = Complex(10, 6)
# Prints the real part
puts num.real()
输出:
10
示例 2 :
# Ruby program for real()
# method in Numeric
# Initialize a number
num = Complex(18, 16)
# Prints the real part
puts num.real()
输出:
18