Open In App

Ruby | Range size() function

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
Article Tags :