红宝石 |设置 reset()函数
reset()是 Ruby 中的一个内置方法,用于在修改现有元素后重置内部状态并返回 self。元素将被重新索引和去重。
Syntax: s1.reset()
Parameters: The function does not accepts any parameter.
Return Value: It returns self .
示例 1 :
# 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()
输出:
Set: {2, 12, 78, 10, 87, 98}
示例 2 :
# 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()
输出:
Set: {1, 2, 4, 3}