Open In App

Ruby | Set reset() function

Last Updated : 12 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
The reset() is an inbuilt method in Ruby resets the internal state after modification to existing elements and returns self. The elements will be reindexed and deduplicated.
Syntax: s1.reset() Parameters: The function does not accepts any parameter. Return Value: It returns self .
Example 1: Ruby
# Ruby program to illustrate 
# the reset() method 
 
# requires the set 
require "set"
 
s1 = Set[2, 12, 78, 10, 87, 98] 
 
# reset method used 
puts s1.reset()
Output:
Set: {2, 12, 78, 10, 87, 98}
Example 2: Ruby
# Ruby program to illustrate 
# the reset() method 
 
# requires the set 
require "set"
 
s1 = Set[1, 2, 4, 3, 2] 
 
# reset method used 
puts s1.reset()
Output:
Set: {1, 2, 4, 3}

Similar Reads