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

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

frozen?

ary.frozen? â true or false Instance Public methods Return true if this array is frozen (or temporarily frozen while being sorted). See also Object#frozen?

hash

ary.hash â fixnum Instance Public methods Compute a hash-code for this array. Two arrays with the same content will have the same hash code (and will compare using eql?).

include?

ary.include?(object) â true or false Instance Public methods Returns true if the given object is present in self (that is, if any element == object), otherwise returns false. a = [ "a", "b", "c" ] a.include?("b") #=> true a.include?("z") #=> false

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.

initialize_copy

ary.replace(other_ary) â ary Instance Public methods Replaces the contents of self with the contents of other_ary, truncating or expanding if necessary. a = [ "a", "b", "c", "d", "e" ] a.replace([ "x", "y", "z" ]) #=> ["x", "y", "z"] a #=> ["x", "y", "z"]

insert

ary.insert(index, obj...) â ary Instance Public methods Inserts the given values before the element with the given index. Negative indices count backwards from the end of the array, where -1 is the last element. a = %w{ a b c d } a.insert(2, 99) #=> ["a", "b", 99, "c", "d"] a.insert(-2, 1, 2, 3) #=> ["a", "b", 99, "c", 1, 2, 3, "d"]

inspect

ary.inspect â stringary.to_s â string Instance Public methods Creates a string representation of self. [ "a", "b", "c" ].to_s #=> "[\"a\", \"b\", \"c\"]" to_s

join

ary.join(separator=$,) â str Instance Public methods Returns a string created by converting each element of the array to a string, separated by the given separator. If the separator is nil, it uses current $,. If both the separator and $, are nil, it uses empty string. [ "a", "b", "c" ].join #=> "abc" [ "a", "b", "c" ].join("-") #=> "a-b-c"