Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Ruby | Numeric i() function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The i() is an inbuilt method in Ruby returns a complex number with the imaginary part that is given.

Syntax: num.i()

Parameters: The function needs a number which is the imaginary part of the complex number.

Return Value: It returns a complex number with the imaginary part.

Example 1:




# Ruby program for i()
# method in Numeric
  
# Initialize a number 
num1 = -10
  
# Prints Complex number
puts num1.i()

Output:

0-10i

Example 2:




# Ruby program for i()
# method in Numeric
  
# Initialize a number 
num1 = 12
  
# Prints Complex number
puts num1.i()

Output:

0+12i
My Personal Notes arrow_drop_up
Last Updated : 06 Jan, 2020
Like Article
Save Article
Similar Reads