[] 2

ary[index] â obj or nilary[start, length] â new_ary or nilary[range] â new_ary or nilary.slice(index) â obj or nilary.slice(start, length) â new_ary or nilary.slice(range) â new_ary or nil Instance Public methods Element Reference â Returns the element at index, or returns a subarray starting at the start index and continuing for length elements, or returns a subarray specified by range of indices. Negative indices co

==

ary == other_ary â bool Instance Public methods Equality â Two arrays are equal if they contain the same number of elements and if each element is equal to (according to Object#==) the corresponding element in other_ary. [ "a", "c" ] == [ "a", "c", 7 ] #=> false [ "a", "c", 7 ] == [ "a", "c", 7 ] #=> true [ "a", "c", 7 ] == [ "a", "d", "f" ] #=> false

<=>

ary other_ary â -1, 0, +1 or nil Instance Public methods Comparison â Returns an integer (-1, 0, or +1) if this array is less than, equal to, or greater than other_ary. nil is returned if the two values are incomparable. Each object in each array is compared (using the <=> operator). Arrays are compared in an âelement-wiseâ manner; the first two elements that are not equal will determine the return value for the whole comparison. If all the values are equal, then the ret

&lt;&lt;

ary Instance Public methods AppendâPushes the given object on to the end of this array. This expression returns the array itself, so several appends may be chained together. [ 1, 2 ] << "c" << "d" << [ 3, 4 ] #=> [ 1, 2, "c", "d", [ 3, 4 ] ]

-

ary - other_ary â new_ary Instance Public methods Array Difference Returns a new array that is a copy of the original array, removing any items that also appear in other_ary. The order is preserved from the original array. It compares elements using their hash and eql? methods for efficiency. [ 1, 1, 2, 2, 3, 3, 4, 5 ] - [ 1, 2, 4 ] #=> [ 3, 3, 5 ] If you need set-like behavior, see the library class Set.

+

ary + other_ary â new_ary Instance Public methods Concatenation â Returns a new array built by concatenating the two arrays together to produce a third array. [ 1, 2, 3 ] + [ 4, 5 ] #=> [ 1, 2, 3, 4, 5 ] a = [ "a", "b", "c" ] a + [ "d", "e", "f" ] a #=> [ "a", "b", "c", "d", "e", "f" ] See also #concat.

*

ary * int â new_aryary * str â new_string Instance Public methods Repetition â With a String argument, equivalent to ary.join(str). Otherwise, returns a new array built by concatenating the int copies of self. [ 1, 2, 3 ] * 3 #=> [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ] [ 1, 2, 3 ] * "," #=> "1,2,3"

&amp;

ary & other_ary â new_ary Instance Public methods Set Intersection â Returns a new array containing elements common to the two arrays, excluding any duplicates. The order is preserved from the original array. It compares elements using their hash and eql? methods for efficiency. [ 1, 1, 3, 5 ] & [ 1, 2, 3 ] #=> [ 1, 3 ] [ 'a', 'b', 'b', 'z' ] & [ 'a', 'b', 'c' ] #=> [ 'a', 'b' ] See also #uniq.

try_convert

Array.try_convert(obj) â array or nil Class Public methods Tries to convert obj into an array, using to_ary method. Returns the converted array or nil if obj cannot be converted for any reason. This method can be used to check if an argument is an array. Array.try_convert([1]) #=> [1] Array.try_convert("1") #=> nil if tmp = Array.try_convert(arg) # the argument is an array elsif tmp = String.try_convert(arg) # the argument is a string end

new

Array.new(size=0, obj=nil)Array.new(array)Array.new(size) {|index| block } Class Public methods Returns a new array. In the first form, if no arguments are sent, the new array will be empty. When a size and an optional obj are sent, an array is created with size copies of obj. Take notice that all elements will reference the same object obj. The second form creates a copy of the array passed as a parameter (the array is generated by calling #to_ary on the parameter). first_array