Related Articles

Related Articles

Ruby | Array sort_by!() function
  • Last Updated : 06 Dec, 2019

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 :



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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"

chevron_right


Output :

sort_by!() method form : #

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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"

chevron_right


Output :

sort_by!() method form : #

sort_by!() method form : #

sort_by!() method form : #

Note : These Enumertor output values can be different depending upon the sysytem.

My Personal Notes arrow_drop_up
Recommended Articles
Page :