Open In App

Ruby | Range size() function

Improve
Improve
Like Article
Like
Save
Share
Report

The size() is an inbuilt method in Ruby returns the size of the range. It returns the number of elements in the range.

Syntax: range1.size()

Parameters: The function accepts no parameter.

Return Value: It returns the number of elements in the range.

Example 1:




# Ruby program for size() 
# method in Range 
  
# Initialize range 
range1 = (0..10)
  
# Prints the size element 
puts range1.size()


Output:

11

Example 2:




# Ruby program for size() 
# method in Range 
  
# Initialize range 
range1 = (4..98)
  
# Prints the size of elements
puts range1.size()


Output:

95

Last Updated : 19 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads