Fetching

Эти методы возвращают элементы из перечисляемого объекта, не изменяя его:

Leading, trailing, or all elements:

  • to_a (aliased as entries): Returns all elements.
  • first: Returns the first element or leading elements.
  • take: Returns a specified number of leading elements.
  • drop: Returns a specified number of trailing elements.
  • take_while: Returns leading elements as specified by the given block.
  • drop_while: Returns trailing elements as specified by the given block.

Minimum and maximum value elements:

  • min: Returns the elements whose values are smallest among the elements, as determined by #<=> or a given block.
  • max: Returns the elements whose values are largest among the elements, as determined by #<=> or a given block.
  • minmax: Returns a 2-element Array containing the smallest and largest elements.
  • min_by: Returns the smallest element, as determined by the given block.
  • max_by: Returns the largest element, as determined by the given block.
  • minmax_by: Returns the smallest and largest elements, as determined by the given block.

Groups, slices, and partitions:

  • group_by: Returns a Hash that partitions the elements into groups.
  • partition: Returns elements partitioned into two new Arrays, as determined by the given block.
  • slice_after: Returns a new Enumerator whose entries are a partition of self, based either on a given object or a given block.
  • slice_before: Returns a new Enumerator whose entries are a partition of self, based either on a given object or a given block.
  • slice_when: Returns a new Enumerator whose entries are a partition of self based on the given block.
  • chunk: Returns elements organized into chunks as specified by the given block.
  • chunk_while: Returns elements organized into chunks as specified by the given block.