Open In App

Ruby | Set flatten!() function

Last Updated : 07 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The flatten!() is an inbuilt method in Ruby replaces the receiver with the result in place. Returns nil if no modifications were made.

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.

Example 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


Output:


Example 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


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads