← Reference

Enumerable

Enumerable mixin methods shared across many collection types.

Enumerable#all?

Returns true if all elements in the collection satisfy the given condition. Returns true for empty collections.

Enumerable#any?

Returns true if any element satisfies the given condition. Checks truthiness when no block or argument is given.

Enumerable#chunk

Group consecutive elements by their block value with chunk in Ruby. Perfect for processing runs, states, or categorized data.

Enumerable#count

Counts elements in a collection that match a condition or returns the total number of elements.

Enumerable#cycle

Call the given block for each element n times or forever. Returns nil if the loop has finished without a break.

Enumerable#drop

Returns all elements after the first n elements. Use drop to skip calibration data, remove headers, or split collections into head and tail.

Enumerable#drop_while

Skips elements from the start of an enumerator while the condition is true, then returns the rest.

Enumerable#each_cons

Process consecutive elements in groups with each_cons. Perfect for sliding window algorithms, pairwise comparisons, and sequential analysis.

Enumerable#each_slice

Iterate over consecutive elements in fixed-size groups with each_slice. Useful for batch processing, pagination, and grouping data into chunks.

Enumerable#each_with_index

Iterates over each element while tracking its index position in the collection.

enum.each_with_index { |item, index| block } -> enum

Enumerable#each_with_object

Iterate over collection while building and returning an accumulator object with each_with_object in Ruby.

Enumerable#filter_map

Filter and transform elements in a single pass with filter_map in Ruby. Combines select and map for efficient processing.

Enumerable#find

Returns the first element that satisfies a given condition. Also available as detect, which is an alias.

Enumerable#first

Returns the first element or first n elements from a collection. Returns nil for empty collections when called without an argument.

Enumerable#flat_map

Transform and flatten collections in one pass with flat_map in Ruby. Combines map and flatten into an efficient operation.

Enumerable#group_by

Groups collection elements by a criteria and returns a hash with keys as group identifiers.

Enumerable#include?

Checks if any element equals the given object. Returns true or false.

Enumerable#inject

Reduces a collection to a single value by applying a binary operation repeatedly. Also known as reduce or fold in other languages.

enum.inject(initial) { |acc, elem| }

Enumerable#map

Returns a new array with the results of running block on every element. Also available as collect, which is an exact synonym.

Enumerable#max

Returns the largest element or n largest elements from an enumerable collection.

Enumerable#max_by

Find the maximum element in a collection based on the return value of a block with max_by in Ruby.

Enumerable#min

Returns the smallest element or n smallest elements from an enumerable collection.

Enumerable#min_by

Find the minimum element in a collection based on the return value of a block with min_by in Ruby.

Enumerable#none?

Returns true if no element satisfies the given condition. Checks for falsy values when no block or argument is given.

Enumerable#partition

Splits a collection into two arrays — elements for which the block returns true, and elements for which it returns false.

Enumerable#reduce

Reduces a collection to a single value by applying a binary operation repeatedly. Also known as inject or fold in other languages.

enum.reduce(initial) { |acc, elem| }

Enumerable#reject

Returns an array of all elements for which the block evaluates to false. The inverse of select — removes elements that match the condition.

Enumerable#select

Returns an array of all elements for which the block evaluates to true. Also available as find_all, which is an exact alias.

Enumerable#sort_by

Sort collection elements by criteria you define with sort_by in Ruby.

Enumerable#sum

Calculates the sum of elements in a collection. Adds all elements together with optional initial value and block transformation.

Enumerable#take

Returns the first n elements from a collection. Returns all elements if n exceeds the collection size — no error is raised.

Enumerable#take_while

Returns elements from the start of a collection while the condition is true. Stops as soon as the condition is false and discards the remaining elements.

Enumerable#tally

Counts occurrences of each element in a collection, returning a hash where keys are elements and values are their counts.

Enumerable#uniq

Returns a new array containing only the unique elements from a collection, preserving original order, with 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.