mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2026-11-29 02:17:42 +08:00
* refactor: clean to roadmap content * refactor: move shared helpers into scripts/lib
9 lines
943 B
Markdown
9 lines
943 B
Markdown
# Sorting in Enumerable
|
|
|
|
The `Enumerable` module in Ruby provides several methods for sorting collections. These methods allow you to arrange elements in ascending or descending order based on their natural ordering or a custom comparison logic. The most common sorting methods include `sort`, which returns a new sorted array, and `sort_by`, which sorts based on the result of a block applied to each element. You can also use `min`, `max`, `minmax` to find the smallest, largest, or both smallest and largest elements in a collection, respectively.
|
|
|
|
Visit the following resources to learn more:
|
|
|
|
- [@article@module Enumerable](https://ruby-doc.org/3.4.1/Enumerable.html#top)
|
|
- [@article@Understanding Ruby - Enumerable - Sorting and Comparing](https://dev.to/baweaver/understanding-ruby-enumerable-sorting-and-comparing-fff)
|
|
- [@article@Sorting short sequences with Enumerable#sort_by](https://silvercat.com/blog/sort-by-unexpected-ordering) |