Why You Would Use ‘.sort_by’ Instead of ‘.sort’ in Ruby

Let’s start by reviewing the ‘.sort’ enumerable.

# In case you didn't know, .sort == .sort { |a, b| a <=> b }# using .sort enumerablenumbers_array = [2,1,3,5,4]numbers_array.Sort #=> [1,2,3,4,5]alphabet_array = ["b", "c", "a"]alphabet_array.sort #=> ["a","b","c"]