Ruby | Array sort_by!() function Last Updated : 24 Jan, 2022 Comments Improve Suggest changes Like Article Like Report Array#sort_by!() : sort_by!() is a Array class method which returns the enumerator for the sorted array. Syntax: Array.sort_by!()Parameter: ArrayReturn: 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. Comment More infoAdvertise with us Next Article Ruby | Array sort_by!() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array sort!() function 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 # Ruby code for sort!() method # declaring array a = ["abc", "nil", "dog"] # declaring 1 min read Ruby | Array sort() function Array#sort() : sort() is a Array class method which returns a new array created by sorting self Syntax: Array.sort() Parameter: Array Return: a new array created by sorting self Example #1 : Ruby # Ruby code for sort() method # declaring array a = ["abc", "nil", "dog"] 1 min read Ruby | Array to_ary() function Array#to_ary() : to_ary() is a Array class method which returns self array representation. Syntax: Array.to_ary() Parameter: Array Return: self array representation. Example #1 : Ruby # Ruby code for to_ary() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 1 min read Ruby | Array shift() function Array#shift() : shift() is a Array class method which removes the first element of self and returns it or nil if the array is empty. Syntax: Array.shift() Parameter: Array Return: removes the first element of self and returns it or nil if the array is empty. Example #1 : Ruby # Ruby code for shift() 2 min read Ruby | Array select!() function Array#select!() : select!() is a Array class method which returns the given block passing in successive elements from self, deleting elements for which the block returns a false value. Syntax: Array.select!() Parameter: Array Return: the given block passing in successive elements from self, deleting 2 min read Like