flatten!

ary.flatten! â ary or nilary.flatten!(level) â ary or nil Instance Public methods Flattens self in place. Returns nil if no modifications were made (i.e., the array contains no subarrays.) The optional level argument determines the level of recursion to flatten. a = [ 1, 2, [3, [4, 5] ] ] a.flatten! #=> [1, 2, 3, 4, 5] a.flatten! #=> nil a #=> [1, 2, 3, 4, 5] a = [ 1, 2, [3, [4, 5] ] ] a.flatten!(1) #=> [1, 2, 3, [4, 5]]

flatten

ary.flatten â new_aryary.flatten(level) â new_ary Instance Public methods Returns a new array that is a one-dimensional flattening of self (recursively). That is, for every element that is an array, extract its elements into the new array. The optional level argument determines the level of recursion to flatten. s = [ 1, 2, 3 ] #=> [1, 2, 3] t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]] a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10] a.flat

first

ary.first â obj or nilary.first(n) â new_ary Instance Public methods Returns the first element, or the first n elements, of the array. If the array is empty, the first form returns nil, and the second form returns an empty array. See also #last for the opposite effect. a = [ "q", "r", "s", "t" ] a.first #=> "q" a.first(2) #=> ["q", "r"]

find_index

ary.index(obj) â int or nilary.index { |item| block } â int or nilary.index â Enumerator Instance Public methods Returns the index of the first object in ary such that the object is == to obj. If a block is given instead of an argument, returns the index of the first object for which the block returns true. Returns nil if no match is found. See also #rindex. An Enumerator is returned if neither a block nor argument is given. a = [ "a", "b", "c" ] a

fill

ary.fill(obj) â aryary.fill(obj, start [, length]) â aryary.fill(obj, range ) â aryary.fill { |index| block } â aryary.fill(start [, length] ) { |index| block } â aryary.fill(range) { |index| block } â ary Instance Public methods The first three forms set the selected elements of self (which may be the entire array) to obj. A start of nil is equivalent to zero. A length of nil is e

fetch

ary.fetch(index) â objary.fetch(index, default) â objary.fetch(index) { |index| block } â obj Instance Public methods Tries to return the element at position index, but throws an IndexError exception if the referenced index lies outside of the array bounds. This error can be prevented by supplying a second argument, which will act as a default value. Alternatively, if a block is given it will only be executed when an invalid index is referenced. Neg

eql?

ary.eql?(other) â true or false Instance Public methods Returns true if self and other are the same object, or are both arrays with the same content (according to Object#eql?).

empty?

ary.empty? â true or false Instance Public methods Returns true if self contains no elements. [].empty? #=> true

each_index

ary.each_index { |index| block } â aryary.each_index â Enumerator Instance Public methods Same as #each, but passes the index of the element instead of the element itself. An Enumerator is returned if no block is given. a = [ "a", "b", "c" ] a.each_index {|x| print x, " -- " } produces: 0 -- 1 -- 2 --

each

ary.each { |item| block } â aryary.each â Enumerator Instance Public methods Calls the given block once for each element in self, passing that element as a parameter. An Enumerator is returned if no block is given. a = [ "a", "b", "c" ] a.each {|x| print x, " -- " } produces: a -- b -- c --