Skip to content
Related Articles
Open in App
Not now

Related Articles

Ruby | Array sort_by!() function

Improve Article
Save Article
  • Last Updated : 24 Jan, 2022
Improve Article
Save Article

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.
 

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!