红宝石 |设置 flatten!()函数
flatten!()是 Ruby 中的一个内置方法,它用适当的结果替换接收器。如果没有进行任何修改,则返回nil 。
Syntax: s1.flatten!()
Parameters: The function does not takes any parameter.
Return Value: It returns the receiver with the result in place, or else returns nil if no changes are made.
示例 1 :
# Ruby program to illustrate the empty method
# requires the set
require "set"
s1 = Set[1, 2, 4, 4]
# flatten method used
s2 = s1.flatten!()
# Prints s2
puts s2
输出:
示例 2 :
# Ruby program to illustrate the empty method
# requires the set
require "set"
s1 = Set[16, 8, 3, 5, 2]
# flatten method used
s2 = s1.flatten!()
# Prints s2
puts s2
输出: