Ruby 数值 i()函数 i() 是Ruby中的一个内置方法,用于返回一个带有给定虚部的复数。 语法 :num.i() 参数 :该函数需要一个数字,即复数的虚部。 返回值 :它返回一个带有虚部的复数。 例子 1 : # Ruby program for i() # method in Numeric # Initialize a number num1 = -10 # Prints Complex number puts num1.i()RubyCopy 输出: 0-10iRubyCopy 例2 : # Ruby program for i() # method in Numeric # Initialize a number num1 = 12 # Prints Complex number puts num1.i()RubyCopy 输出: 0+12iRubyCopy