combination

ary.combination(n) { |c| block } â aryary.combination(n) â Enumerator Instance Public methods When invoked with a block, yields all combinations of length n of elements from the array and then returns the array itself. The implementation makes no guarantees about the order in which the combinations are yielded. If no block is given, an Enumerator is returned instead. Examples: a = [1, 2, 3, 4] a.combination(1).to_a #=> [[1],[2],[3],[4]] a.combination(2).to_

compact

ary.compact â new_ary Instance Public methods Returns a copy of self with all nil elements removed. [ "a", nil, "b", nil, "c", nil ].compact #=> [ "a", "b", "c" ]

compact!

ary.compact! â ary or nil Instance Public methods Removes nil elements from the array. Returns nil if no changes were made, otherwise returns the array. [ "a", nil, "b", nil, "c" ].compact! #=> [ "a", "b", "c" ] [ "a", "b", "c" ].compact! #=> nil

concat

ary.concat(other_ary) â ary Instance Public methods Appends the elements of other_ary to self. [ "a", "b" ].concat( ["c", "d"] ) #=> [ "a", "b", "c", "d" ] a = [ 1, 2, 3 ] a.concat( [ 4, 5 ] ) a #=> [ 1, 2, 3, 4, 5 ] See also Array#+.

count

ary.count â intary.count(obj) â intary.count { |item| block } â int Instance Public methods Returns the number of elements. If an argument is given, counts the number of elements which equal obj using ===. If a block is given, counts the number of elements for which the block returns a true value. ary = [1, 2, 4, 2] ary.count #=> 4 ary.count(2) #=> 2 ary.count { |x| x%2 == 0 } #=> 3

cycle

ary.cycle(n=nil) { |obj| block } â nilary.cycle(n=nil) â Enumerator Instance Public methods Calls the given block for each element n times or forever if nil is given. Does nothing if a non-positive number is given or the array is empty. Returns nil if the loop has finished without getting interrupted. If no block is given, an Enumerator is returned instead. a = ["a", "b", "c"] a.cycle { |x| puts x } # print, a, b, c, a, b, c,.. forever. a.cycle(2) { |x| puts

dclone

dclone() Instance Public methods provides a unified clone operation, for REXML::XPathParser to use across multiple Object+ types

delete

ary.delete(obj) â item or nilary.delete(obj) { block } â item or result of block Instance Public methods Deletes all items from self that are equal to obj. Returns the last deleted item, or nil if no matching item is found. If the optional code block is given, the result of the block is returned if the item is not found. (To remove nil elements and get an informative return value, use #compact!) a = [ "a", "b", "b", "b", "c" ] a.delete("b") #=> "b

delete_at

ary.delete_at(index) â obj or nil Instance Public methods Deletes the element at the specified index, returning that element, or nil if the index is out of range. See also #slice! a = ["ant", "bat", "cat", "dog"] a.delete_at(2) #=> "cat" a #=> ["ant", "bat", "dog"] a.delete_at(99) #=> nil

delete_if

ary.delete_if { |item| block } â aryary.delete_if â Enumerator Instance Public methods Deletes every element of self for which block evaluates to true. The array is changed instantly every time the block is called, not after the iteration is over. See also #reject! If no block is given, an Enumerator is returned instead. a = [ "a", "b", "c" ] a.delete_if {|x| x >= "b" } #=> ["a"]