红宝石 |数值 rect()函数
rect()是 Ruby 中的一个内置方法,它返回一个由实数和虚数组成的数组。
Syntax: num.rect()
Parameters: The function needs the number whose real and imaginary part is returned.
Return Value: It returns an array which consists of a real and an imaginary number.
示例 1 :
# Ruby program for rect()
# method in Numeric
# Initialize a number
num = Complex(10, 6)
# Prints the rect part
puts num.rect()
输出:
10
6
示例 2 :
# Ruby program for rect()
# method in Numeric
# Initialize a number
num = Complex(18, 16)
# Prints the rect part
puts num.rect()
输出:
18
16