member?

enum.member?(obj) â true or false Instance Public methods Returns true if any member of enum equals obj. Equality is tested using ==. IO.constants.include? :SEEK_SET #=> true IO.constants.include? :SEEK_NO_FURTHER #=> false

max_by

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

max

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

map

enum.map { |obj| block } â arrayenum.map â an_enumerator Instance Public methods Returns a new array with the results of running block once for every element in enum. If no block is given, an enumerator is returned instead. (1..4).collect { |i| i*i } #=> [1, 4, 9, 16] (1..4).collect { "cat" } #=> ["cat", "cat", "cat", "cat"]

lazy

e.lazy â lazy_enumerator Instance Public methods Returns a lazy enumerator, whose methods map/collect, flat_map/collect_concat, select/find_all, reject, grep, zip, take, #take_while, drop, and #drop_while enumerate values only on an as-needed basis. However, if a block is given to zip, values are enumerated immediately. Example The following program finds pythagorean triples: def pythagorean_triples (1..Float::INFINITY).lazy.flat_map {|z| (1..z).flat_map {|x| (x..z).s

inject

enum.inject(initial, sym) â objenum.inject(sym) â objenum.inject(initial) { |memo, obj| block } â objenum.inject { |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

include?

enum.include?(obj) â true or false Instance Public methods Returns true if any member of enum equals obj. Equality is tested using ==. IO.constants.include? :SEEK_SET #=> true IO.constants.include? :SEEK_NO_FURTHER #=> false

group_by

enum.group_by { |obj| block } â a_hashenum.group_by â an_enumerator Instance Public methods Groups the collection by result of the block. Returns a hash where the keys are the evaluated result from the block and the values are arrays of elements in the collection that correspond to the key. If no block is given an enumerator is returned. (1..6).group_by { |i| i%3 } #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}

grep

enum.grep(pattern) â arrayenum.grep(pattern) { |obj| block } â array Instance Public methods Returns an array of every element in enum for which Pattern === element. If the optional block is supplied, each matching element is passed to it, and the block's result is stored in the output array. (1..100).grep 38..44 #=> [38, 39, 40, 41, 42, 43, 44] c = IO.constants c.grep(/SEEK/) #=> [:SEEK_SET, :SEEK_CUR, :SEEK_END] res = c.grep(/SEEK/) { |v| IO.con

flat_map

enum.flat_map { |obj| block } â arrayenum.flat_map â an_enumerator Instance Public methods Returns a new array with the concatenated results of running block once for every element in enum. If no block is given, an enumerator is returned instead. [1, 2, 3, 4].flat_map { |e| [e, -e] } #=> [1, -1, 2, -2, 3, -3, 4, -4] [[1, 2], [3, 4]].flat_map { |e| e + [100] } #=> [1, 2, 100, 3, 4, 100]