Check out example codes for "returning objects in alphabetical order in ruby". It will help you in understanding the concepts better.

Code Example 1

[p1, p2, p3, p4].sort_by { |p| [p.fname, p.lname] }

Learn ReactJs, React Native from akashmittal.com