Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Range size() function

  • Last Updated : 06 Jan, 2020
Geek Week

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