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