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() |
chevron_right
filter_none
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() |
chevron_right
filter_none
Output:
3
Recommended Posts:
- Ruby | Struct length() function
- Ruby | SizedQueue length() function
- Ruby | Queue length() function
- Ruby | Symbol length function
- Ruby | Array length() function
- Ruby | String length Method
- Ruby | Hash length() method
- Ruby | Set replace() function
- Ruby | Set reset() function
- Ruby | Set merge() function
- Ruby | Set member?() function
- Ruby | Set include?() function
- Ruby | Set delete? function
- Ruby | Set delete() function
- Ruby | Set compare_by_identity? function
- Ruby | Set compare_by_identity() function
- Ruby | Set add? function
- Ruby | Set clear() function
- Ruby | Set difference() function
- Ruby | Set disjoint? function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

