Horje
Ruby | Rational numerator() function

The numerator() is an inbuilt function in Ruby returns the numerator.

Syntax: rat.numerator()

Parameters: The function accepts no parameter

Return Value: It returns the numerator

Example 1:




# Ruby program for numerator() method
  
# Initialize rational number
rat1 = Rational(7, -3)
  
# Prints the rational number
puts rat1.numeratorr()

Output:

-7

Example 2:




# Ruby program for numerator() method
  
# Initialize rational number
rat1 = Rational(7)
  
# Prints the rational number
puts rat1.numerator()

Output:

7



Reffered: https://www.geeksforgeeks.org


Ruby

Related
Ruby | Rational inspect() function Ruby | Rational inspect() function
Ruby | Numeric truncate() function Ruby | Numeric truncate() function
Ruby | Rational floor() function Ruby | Rational floor() function
Ruby | Numeric to_int() function Ruby | Numeric to_int() function
Ruby | Rational fdiv() function Ruby | Rational fdiv() function

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
6