Open In App

Ruby | Numeric real() function

Last Updated : 19 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The real() is an inbuilt method in Ruby returns the real part of the given number.

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.

Example 1:




# Ruby program for real()
# method in Numeric
  
# Initialize a number 
num = Complex(10, 6)
  
# Prints the real part
puts num.real()


Output:

10

Example 2:




# Ruby program for real()
# method in Numeric
  
# Initialize a number 
num = Complex(18, 16)
  
# Prints the real part
puts num.real()


Output:

18

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads