Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically unpack Tuple when sorting arrays
Avoid capturing the block used for sorting, allowing automatic unpacking of Tuples. Since the block is only required in the inner `#quicksort!` function, this change gives some flexibility to the user allowing them write more expressive code. In the following example: a = [{"c", 3}, {"a", 1}, {"b", 2}] a.sort_by &.[1] a.sort_by { |(x, y)| y } Both `sort_by` calls produce the same result, one being more cryptic and the other being explicit about unpacking. In comparison: a.sort_by { |x, y| y } Produces the same results more transparently to the developer writing the code and behaves similar to other methods that perform automatic unpack like `#map` or `#each`. Performance-wise, this change does introduce a speedup on synthetic benchmarks: sort_by: 2.29M (± 1.03%) 1.10× slower sort_by (new): 2.51M (± 0.99%) fastest Fixes #3419