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.

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

select

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

slice_before

enum.slice_before(pattern) â an_enumeratorenum.slice_before { |elt| bool } â an_enumeratorenum.slice_before(initial_state) { |elt, state| bool } â an_enumerator Instance Public methods Creates an enumerator for each chunked elements. The beginnings of chunks are defined by pattern and the block. If pattern === elt returns true or the block returns true for the element, the element is beginning of a chunk. The === and block is calle

sort

enum.sort â arrayenum.sort { |a, b| block } â array Instance Public methods Returns an array containing the items in enum sorted, either according to their own <=> method, or by using the results of the supplied block. The block should return -1, 0, or +1 depending on the comparison between a and b. As of Ruby 1.8, the method Enumerable#sort_by implements a built-in Schwartzian Transform, useful when key computation or comparison is expensive. %w(rhea kea fl

sort_by

enum.sort_by { |obj| block } â arrayenum.sort_by â an_enumerator Instance Public methods Sorts enum using a set of keys generated by mapping the values in enum through the given block. If no block is given, an enumerator is returned instead. %w{apple pear fig}.sort_by { |word| word.length} #=> ["fig", "pear", "apple"] The current implementation of sort_by generates an array of tuples containing the original collection element and the mapped va

take

enum.take(n) â array Instance Public methods Returns first n elements from enum. a = [1, 2, 3, 4, 5, 0] a.take(3) #=> [1, 2, 3]

take_while

enum.take_while { |arr| block } â arrayenum.take_while â an_enumerator Instance Public methods Passes elements to the block until the block returns nil or false, then stops iterating and returns an array of all prior elements. If no block is given, an enumerator is returned instead. a = [1, 2, 3, 4, 5, 0] a.take_while { |i| i < 3 } #=> [1, 2]

to_a

enum.to_a â array Instance Public methods Returns an array containing the items in enum. (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7] { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]

to_set

to_set(klass = Set, *args, &block) Instance Public methods Makes a set from the enumerable object with given arguments. Needs to +require âsetâ+ to use this method.