Skip to content
Related Articles

Related Articles

Ruby | Set length() function
  • Last Updated : 07 Jan, 2020
GeeksforGeeks - Summer Carnival Banner

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

Syntax: s1_name.length()

Parameters: The function does not accepts any parameter.

Return Value: It returns the size of the set.

Example 1:






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

Output:

5

Example 2:




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

Output:

3

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :