Ruby | Set size() function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like 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 # 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 # 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 Comment More infoAdvertise with us Next Article Ruby | SizedQueue shift() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Set-class Similar Reads Ruby | SizedQueue size() function The size() is an inbuilt function in Ruby returns the current size of the SizedQueue or the number of objects present in it. Syntax: sq_name.size() Parameters: The function does not takes any parameter. Return Value: It returns the number of elements in the SizedQueue. Example 1: CPP #Ruby program f 1 min read Ruby | SizedQueue size() function The size() is an inbuilt function in Ruby returns the current size of the SizedQueue or the number of objects present in it. Syntax: sq_name.size() Parameters: The function does not takes any parameter. Return Value: It returns the number of elements in the SizedQueue. Example 1: CPP #Ruby program f 1 min read Ruby | SizedQueue shift() function The shift() is an inbuilt function in Ruby returns the element in the front of the SizedQueue and removes it from the SizedQueue. Syntax: sq_name.shift() Parameters: The function does not takes any element. Return Value: It returns the first element which is at the front of the SizedQueue and remove 1 min read Ruby | SizedQueue shift() function The shift() is an inbuilt function in Ruby returns the element in the front of the SizedQueue and removes it from the SizedQueue. Syntax: sq_name.shift() Parameters: The function does not takes any element. Return Value: It returns the first element which is at the front of the SizedQueue and remove 1 min read Ruby | Set add? function The add? is an inbuilt method in Ruby which adds the given object to the set and returns self. If the object is already in the set, returns nil. Syntax: s1.name.add?(object) Parameters: The function takes the object to be added to the set. Return Value: It returns self if the object is not in the se 1 min read Ruby | Set add? function The add? is an inbuilt method in Ruby which adds the given object to the set and returns self. If the object is already in the set, returns nil. Syntax: s1.name.add?(object) Parameters: The function takes the object to be added to the set. Return Value: It returns self if the object is not in the se 1 min read Like