Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Numeric real() function

  • Last Updated : 06 Jan, 2020

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
My Personal Notes arrow_drop_up
Recommended Articles
Page :