Open In App

Ruby | Numeric real() function

Last Updated : 19 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
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
# 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
# Ruby program for real()
# method in Numeric

# Initialize a number 
num = Complex(18, 16)

# Prints the real part
puts num.real()
Output:
18

Next Article

Similar Reads