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:
range1 = ( 0 .. 10 )
puts range1.size()
|
Output:
11
Example 2:
range1 = ( 4 .. 98 )
puts range1.size()
|
Output:
95
Last Updated :
19 Mar, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...