Reason #14 • January 14th, 2026

Enumerable#partition

We'll keep it short and sweet on the third day of Enumerable week: let's look at Enumerable#partition.

You can think of partition as a select (or filter for JavaScript folks) that returns two arrays: the first for elements that match the condition and the second for those that don't. It goes hand in hand with Ruby's ability to capture multiple return values via parallel assignment.

Ruby
numbers = [1, 2, 3, 4, 5, 6]
even_numbers, odd_numbers = numbers.partition(&:even?)
# => even_numbers: [2, 4, 6]
# => odd_numbers: [1, 3, 5]
      
JavaScript
const numbers = [1, 2, 3, 4, 5, 6];
const evenNumbers = numbers.filter(n => n % 2 === 0);
const oddNumbers = numbers.filter(n => n % 2 !== 0);
// => evenNumbers: [2, 4, 6]
// => oddNumbers: [1, 3, 5]
      

This one came to mind when I hit a situation in a pull request review just the other day where partition was the perfect fit:

The partition method was added to Enumerable in Ruby 1.8.0, released in 2003.

Reason #15 ?