Skip to content
Related Articles
Open in App
Not now

Related Articles

Ruby | Array sort!() function

Improve Article
Save Article
  • Last Updated : 06 Dec, 2019
Improve Article
Save Article

Array#sort!() : sort!() is a Array class method which returns sorted self array in place.

Syntax: Array.sort!()

Parameter: Array

Return: sorted self array in place.

Example #1 :




# Ruby code for sort!() method
  
# declaring array
a = ["abc", "nil", "dog"]
  
# declaring array
c = ["cat", "efg", "geeks"]
  
# declaring array
b = ["cow", "coal", "dog"]
  
arr = [a, b, c]
  
# sort! method example
puts "sort!() method form : #{arr.sort!()}\n\n"


Output :

sort!() method form : [["abc", "nil", "dog"], ["cat", "efg", "geeks"], ["cow", "coal", "dog"]]

Example #2 :




# Ruby code for sort!() method
  
# declaring array
a = ["abc", "nil", "dog"]
  
# declaring array
c = ["cat", "efg", "geeks"]
  
# declaring array
b = ["cow", "coal", "dog"]
  
  
# sort! method example
puts "sort!() method form : #{a.sort!()}\n\n"
  
puts "sort!() method form : #{b.sort!()}\n\n"
  
puts "sort!() method form : #{c.sort!()}\n\n"


Output :

sort!() method form : ["abc", "dog", "nil"]

sort!() method form : ["coal", "cow", "dog"]

sort!() method form : ["cat", "efg", "geeks"]


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!