Use Enumerable#all? to check if every element in a Ruby collection passes a test. Covers blocks, patterns, short-circuit eval, and empty-collection quirks.
Reference
Enumerable
Enumerable mixin methods shared across many collection types.
- Enumerable#all?
- Enumerable#any?
Enumerable#any? returns true when at least one element satisfies a condition, making it a fast yes-or-no check for Ruby collections.
- Enumerable#chunk
Enumerable#chunk groups consecutive Ruby elements by the value returned from a block. It is useful for runs, states, and categorized data.
- Enumerable#count
Enumerable#count returns the number of elements in a Ruby collection. It can count everything, matching values, or block results.
- Enumerable#cycle
Enumerable#cycle repeats each element n times or forever, returning nil when the loop finishes without a break.
- Enumerable#drop
Enumerable#drop returns all elements after the first n items. Use it to skip calibration data, remove headers, or split a collection into head and tail.
- Enumerable#drop_while
Enumerable#drop_while skips leading elements while a condition holds, returning the rest as an array. Strip prefixes from Ruby sequences with a clear predicate.
- Enumerable#each_cons
Enumerable#each_cons processes consecutive elements in groups, which is useful for sliding windows, pairwise comparisons, and sequential analysis.
- Enumerable#each_slice
Enumerable#each_slice iterates over consecutive elements in fixed-size groups. An essential Ruby enumerable for batch processing, pagination, and chunking data.
- Enumerable#each_with_index
Ruby's Enumerable#each_with_index iterates elements with their index, useful for numbered lists, pairing parallel arrays, and position-based lookups.
- Enumerable#each_with_object
Ruby's Enumerable#each_with_object iterates collections while building a mutable accumulator like a hash or array, returned intact after the loop.
- Enumerable#filter_map
Combine select and map into one efficient pass with Enumerable#filter_map. Filter and transform enumerable elements without building intermediate arrays.
- Enumerable#find
Enumerable#find returns the first element in a collection that matches a given condition, short-circuiting iteration as soon as a match is found in Ruby.
- Enumerable#first
Enumerable#first gets the first element or first n elements from any collection with the Enumerable mixin. Returns nil on empty, [] when passed n.
- Enumerable#flat_map
Enumerable#flat_map transforms each element and flattens the result by one level. It combines map and flatten in a single Ruby pass.
- Enumerable#group_by
Enumerable#group_by organizes Ruby collections into buckets by a shared trait, returning a hash keyed by group identifier with matching element arrays.
- Enumerable#include?
Enumerable#include? checks whether a Ruby collection contains a matching element. It returns true or false and uses == for comparisons.
- Enumerable#inject
Accumulate collections into single values with Ruby's Enumerable#inject. Covers summing, max finding, string building, flattening, and the reduce alias.
- Enumerable#map
Transform collections with Ruby's Enumerable#map, returning a new array of block results. Covers the collect alias, chaining, lazy evaluation, and hash mapping.
- Enumerable#max
Returns the largest element or the n largest elements from an enumerable collection using natural order or a custom comparison block.
- Enumerable#max_by
Use max_by in Ruby to find the maximum element in any enumerable by custom comparison logic. Rank by derived values, distance, or any scoring function.
- Enumerable#min
Ruby's Enumerable#min returns the smallest element or n smallest elements from a collection, supporting custom comparison blocks for flexible ordering.
- Enumerable#min_by
Enumerable#min_by finds the minimum element in a collection using a block. Covers ranking by computed values, finding multiple minima, and practical examples.
- Enumerable#none?
Use Enumerable#none? to check if no element satisfies a condition in a Ruby collection, returning a boolean after testing a block, pattern, or truthiness.
- Enumerable#partition
Use the Enumerable partition method to split a Ruby collection into two arrays in one pass — one for truthy block results, one for falsy.
- Enumerable#reduce
Collapse collections into single values with Ruby's Enumerable#reduce. Covers summing, maxima, building strings, flattening arrays, and the inject alias.
- Enumerable#reject
Filter collections with Ruby's Enumerable#reject, the inverse of select. Removes matching elements. Examples for arrays, hashes, and method chaining.
- Enumerable#select
Enumerable#select returns all elements for which a block evaluates to true, making it the core enumerable method for filtering Ruby collections by condition.
- Enumerable#sort_by
Sort enumerable collection elements by criteria you define with sort_by in Ruby, which is useful for custom ordering and natural comparison rules.
- Enumerable#sum
Enumerable#sum calculates totals for numbers, strings, hashes, and ranges with an optional initial value or block.
- Enumerable#take
Enumerable#take returns the first n elements from any Ruby collection. Use it for previewing data, limiting result sets, and splitting head from tail.
- Enumerable#take_while
Returns elements from the start of an enumerable while the condition is true, then stops as soon as the condition is false and discards the remaining elements.
- Enumerable#tally
Counts occurrences of each element in an enumerable collection in Ruby, returning a hash where keys are elements and values are their counts.
- Enumerable#uniq
Enumerable#uniq returns a new array of unique elements from a collection, preserving insertion order with an optional block for custom uniqueness logic.
- Enumerable#zip
Merge multiple enumerables element-by-element with zip in Ruby. Creates arrays of corresponding elements, filling shorter ones with nil.