reverse_each

enum.reverse_each(*args) { |item| block } â enumenum.reverse_each(*args) â an_enumerator Instance Public methods Builds a temporary array and traverses that array in reverse order. If no block is given, an enumerator is returned instead. (1..3).reverse_each { |v| p v } produces: 3 2 1

reject

enum.reject { |obj| block } â arrayenum.reject â an_enumerator Instance Public methods Returns an array for all elements of enum for which the given block returns false. If no block is given, an Enumerator is returned instead. (1..10).reject { |i| i % 3 == 0 } #=> [1, 2, 4, 5, 7, 8, 10] [1, 2, 3, 4, 5].reject { |num| num.even? } #=> [1, 3, 5] See also #find_all.

reduce

enum.reduce(initial, sym) â objenum.reduce(sym) â objenum.reduce(initial) { |memo, obj| block } â objenum.reduce { |memo, obj| block } â obj Instance Public methods Combines all elements of enum by applying a binary operation, specified by a block or a symbol that names a method or operator. If you specify a block, then for each element in enum the block is passed an accumulator value (memo) and the element. If you specify a symbol instead, then each element in

partition

enum.partition { |obj| block } â [ true_array, false_array ]enum.partition â an_enumerator Instance Public methods Returns two arrays, the first containing the elements of enum for which the block evaluates to true, the second containing the rest. If no block is given, an enumerator is returned instead. (1..6).partition { |v| v.even? } #=> [[2, 4, 6], [1, 3, 5]]

one?

enum.one? [{ |obj| block }] â true or false Instance Public methods Passes each element of the collection to the given block. The method returns true if the block returns true exactly once. If the block is not given, one? will return true only if exactly one of the collection members is true. %w{ant bear cat}.one? { |word| word.length == 4 } #=> true %w{ant bear cat}.one? { |word| word.length > 4 } #=> false %w{ant bear cat}.one? { |word| word.length < 4 } #=>

none?

enum.none? [{ |obj| block }] â true or false Instance Public methods Passes each element of the collection to the given block. The method returns true if the block never returns true for all elements. If the block is not given, none? will return true only if none of the collection members is true. %w{ant bear cat}.none? { |word| word.length == 5 } #=> true %w{ant bear cat}.none? { |word| word.length >= 4 } #=> false [].none? #=&

minmax_by

enum.minmax_by { |obj| block } â [min, max]enum.minmax_by â an_enumerator Instance Public methods Returns a two element array containing the objects in enum that correspond to the minimum and maximum values respectively from the given block. If no block is given, an enumerator is returned instead. a = %w(albatross dog horse) a.minmax_by { |x| x.length } #=> ["dog", "albatross"]

minmax

enum.minmax â [min, max]enum.minmax { |a, b| block } â [min, max] Instance Public methods Returns two elements array which contains the minimum and the maximum value in the enumerable. The first form assumes all objects implement Comparable; the second uses the block to return a <=> b. a = %w(albatross dog horse) a.minmax #=> ["albatross", "horse"] a.minmax { |a, b| a.length <=> b.length } #=> ["dog", "albatross"

min_by

enum.min_by { |obj| block } â objenum.min_by â an_enumerator Instance Public methods Returns the object in enum that gives the minimum value from the given block. If no block is given, an enumerator is returned instead. a = %w(albatross dog horse) a.min_by { |x| x.length } #=> "dog"

min

enum.min â objenum.min { |a, b| block } â obj Instance Public methods Returns the object in enum with the minimum value. The first form assumes all objects implement Comparable; the second uses the block to return a <=> b. a = %w(albatross dog horse) a.min #=> "albatross" a.min { |a, b| a.length <=> b.length } #=> "dog"