Array Flashcards
Ruby Array
return the first n elements of an array
take(n) => new_ary
Ruby Array
return a new array containing elements common to the two arrays
ary & other_ary => new_ary
Ruby Array
return a new array built by concatenating the two arrays together to produce a third array
concat(other_ary) => ary
Ruby Array
return a new array that is a copy of the original array, removing any items that also appear in other_ayr
ary - other_ary => new_ary
Ruby Array
append - pushes the given object to the end of this array
ary << obj => ary
Ruby Array
search through an array whose elements are also arrays comparing obj with the first element of each contained array; return the first contained array that matches, or nil if no match is found
assoc(obj) => element_ary or nil
Ruby Array
return the element at index; a negative index counts from the end of self; return nil if the index is out of range
at(index) => obj or nil
Ruby Array
remove all elements of self
clear => ary
Ruby Array
yield all combinations of length n of elements from the array
combination(n) => Enumerator
Ruby Array
return a copy of self with all nil elements removed
compact => new_ary
Ruby Array
alias for Array#concat
ary + other_ary => new_ary
Ruby Array
return the number of elements; if an argument is given, return the number of elements that == obj; if a block is given, return the number of elements for which the block returns true
count => int
count(obj) => int
count { |item| block } => int
Ruby Array
call the given block n times for each element or forever if nil is given
cycle(n=nil) { |obj| block }
Ruby Array
delete all items from self that == obj
delete(obj) => item or nil
Ruby Array
delete the element at the specified index, returning that element or nil if the index is out of range
delete_at(index) => obj or nil
Ruby Array
return a new array containing elements in self for which the given block is not true
reject { |item| block } => new_ary
Ruby Array
drop first n elements from ary and returns the remaining elements in an array
drop(n) => new_ary
Ruby Array
drop elements up to, but not including, the first element for which the block returns nil or false and return an array containing the remaining elements
drop_while { |obj| block } => new_ary
Ruby Array
call the given block once for each element in self, passing that element as a parameter; return the array itself
each { |item| block } => ary
Ruby Array
same as Array#each, but passes the index of the element instead of the element itself
each_index { |index| block } => ary
Ruby Array
return true if self contains no elements
empty? => true or false
Ruby Array
set the selected elements of self to obj; if a block is given, fills the array with the value of the block, which is passed the index of each element to be filled
fill(obj) => ary
fill(obj, start [, length]) => ary
fill(obj, range) => ary
fill { |index| block } => ary
fill(start [, length]) { |index| block} => ary
fill(range) { |index| block } => ary
Ruby Array
return the index of the first element that == obj; if a block is given, return the index of the first element for which the block returns true
find_index(obj) => int or nil
find_index { |item| block } => int or nil
Ruby Array
return the first n elements of self
first => obj or nil
first(n) => new_ary
Ruby Array
return a new array that is a one-dimensional flattening of self; optional level argument determines the level of recursion to flatten
flatten => new_ary
flatten(level) => new_ary
Ruby Array
return true if obj is present in self (any element == obj)
include?(obj) => true or false
Ruby Array
return the index of the first element of self that == obj; if a block is given, return the first element for which the block returns true
index(obj) => int or nil
index { |item| block } => int or nil
Ruby Array
insert the given values before the element at the specified index; if a negative index is given, the elements are inserted after the element that index (i.e. -1 adds to the end of the array)
insert(index, obj…) => ary
Ruby Array
return a string created by converting each element of self to a string, separated by the given separator or an empty string
join(separator=$,) => str
Ruby Array
return the last n elements of self
last => obj or nil
last(n) => new_ary
Ruby Array
return the number of elements in self
length => int
Ruby Array
return a new array containing the values returned by the block, which is invoked once for each element of self
map { |item| block } => new_ary
Ruby Array
yield all permutations of length n of the elements of self, then return the array itself
permutation(n) => Enumerator
permutation(n) { |p| block } => ary
Ruby Array
remove the last n elements of self and return them
pop => obj or nil
pop(n) => new_ary
Ruby Array
return an array of all combinations of elements of all arrays
product(other_ary, …) => new_ary
Ruby Array
append - push the given object(s) on to the end of self, returning the array itself
push(obj, …) => ary
Ruby Array
search through self whose elements are also arrays; compare obj with the second element of each contained array; return the first contained array that matches obj
rassoc(obj) => element or nil
Ruby Array
yield all repeated combinations of length n of elements of self then returns the array itself
repeated_combination(n) => Enumerator
Ruby Array
yield all repeated permuations of length n of the elements of self, then return the array itself
repeated_permutation(n) => Enumerator
Ruby Array
return a new array containing self’s elements in reverse order
reverse => new_ary
Ruby Array
same as Array#each but traverses self in reverse order
reverse_each { |item| block } => ary
Ruby Array
return the index of the last element in self that == obj; if a block is given, return the index of the last element in self for which the block returns true
rindex(obj) => int or nil
rindex(obj) { |item| block } => int or nil
Ruby Array
return a new array by rotating self so that the element at count is the first element of the new array
rotate(count=1) => new_ary
Ruby Array
choose a random element or n random elements from self
sample => obj
sample(n) => new_ary