What is the integer.numerator property in Ruby?

Overview

In Ruby, the numerator property of an integer is used to get the numerator of an integer value.

Syntax

intValue.numerator

Return value

This property returns the integer itself.

Example

# create integer values
int1 = 20
int2 = 4
int3 = 34
int4 = -3
# get the numerator
puts int1.numerator
puts int2.numerator
puts int3.numerator
puts int4.numerator

Explanation

  • Line 2–5: We create some integer values.
  • Line 8–11: We use the numerator property to get the numerator of the integer values. Next, we print the output.

Free Resources