Open In App

Ruby | Set size() function

Improve
Improve
Like Article
Like
Save
Share
Report

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

Syntax: s1_name.size()

Parameters: The function does not accepts any parameter.

Return Value: It returns the size of the set.

Example 1:




# Ruby program to illustrate 
# the size method 
   
# requires the set 
require "set"
   
s1 = Set[16, 8, 3, 5, 2]
   
# size method used
puts s1.size()


Output:

5

Example 2:




# Ruby program to illustrate 
# the size method 
   
# requires the set 
require "set"
   
s1 = Set[1, 2, 5]
   
# size method used
puts s1.size()


Output:

3

Last Updated : 07 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads