Skip to content
Related Articles

Related Articles

Ruby | Set flatten!() function
  • Last Updated : 07 Jan, 2020
GeeksforGeeks - Summer Carnival Banner

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:


Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :