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" ]

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_

collect!

ary.collect! {|item| block } â aryary.collect! â Enumerator Instance Public methods Invokes the given block once for each element of self, replacing the element with the value returned by the block. See also Enumerable#collect. If no block is given, an Enumerator is returned instead. a = [ "a", "b", "c", "d" ] a.map! {|x| x + "!" } a #=> [ "a!", "b!", "c!", "d!" ]

collect

ary.collect { |item| block } â new_aryary.collect â Enumerator Instance Public methods Invokes the given block once for each element of self. Creates a new array containing the values returned by the block. See also Enumerable#collect. If no block is given, an Enumerator is returned instead. a = [ "a", "b", "c", "d" ] a.map { |x| x + "!" } #=> ["a!", "b!", "c!", "d!"] a #=> ["a", "b", "c", "d"]

clear

ary.clear â ary Instance Public methods Removes all elements from self. a = [ "a", "b", "c", "d", "e" ] a.clear #=> [ ]

bsearch

ary.bsearch {|x| block } â elem Instance Public methods By using binary search, finds a value from this array which meets the given condition in O(log n) where n is the size of the array. You can use this method in two use cases: a find-minimum mode and a find-any mode. In either case, the elements of the array must be monotone (or sorted) with respect to the block. In find-minimum mode (this is a good choice for typical use case), the block must return true or false, and there

at

ary.at(index) â obj or nil Instance Public methods Returns the element at index. A negative index counts from the end of self. Returns nil if the index is out of range. See also #[]. a = [ "a", "b", "c", "d", "e" ] a.at(0) #=> "a" a.at(-1) #=> "e"

assoc

ary.assoc(obj) â new_ary or nil Instance Public methods Searches through an array whose elements are also arrays comparing obj with the first element of each contained array using obj.==. Returns the first contained array that matches (that is, the first associated array), or nil if no match is found. See also #rassoc s1 = [ "colors", "red", "blue", "green" ] s2 = [ "letters", "a", "b", "c" ] s3 = "foo" a = [ s1, s2, s3 ] a.assoc("letters") #=> [ "letters", "a", "b", "c"

abbrev

abbrev(pattern = nil) Instance Public methods Calculates the set of unambiguous abbreviations for the strings in self. require 'abbrev' %w{ car cone }.abbrev #=> {"ca" => "car", "con"=>"cone", "co" => "cone", "car"=>"car", "cone" => "cone"} The optional pattern parameter is a pattern or a string. Only input strings that match the pattern or start with the string are included in the output hash. %w{ fast boat day }.abbrev(/^.a/) #=> {"fas"=>"fast", "fa"=

[]=

ary[index] = obj â objary[start, length] = obj or other_ary or nil â obj or other_ary or nilary[range] = obj or other_ary or nil â obj or other_ary or nil Instance Public methods Element Assignment â Sets the element at index, or replaces a subarray from the start index for length elements, or replaces a subarray specified by the range of indices. If indices are greater than the current capacity of the array, the array grows automatically.