Open In App

Ruby | Array sort_by!() function

Last Updated : 24 Jan, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Array#sort_by!() : sort_by!() is a Array class method which returns the enumerator for the sorted array.
 

Syntax: Array.sort_by!()
Parameter: Array
Return: the enumerator for the sorted array.

Example #1 :
 

Ruby




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


Output : 
 

sort_by!() method form : #

Example #2 : 
 

Ruby




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


Output : 
 

sort_by!() method form : #

sort_by!() method form : #

sort_by!() method form : #

Note : These Enumerator output values can be different depending upon the system.
 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads