Loading...
Preparing your coding drills
Comprehensive reference for 43 Ruby methods across 3 categories.
push
Appends one or more elements to the end of the array.
pop
Removes and returns the last element.
shift
Removes and returns the first element.
unshift
Prepends one or more elements to the beginning.
map
Returns a new array with results of running block for every element.
select
Returns array of elements for which block returns true.
reject
Returns array excluding elements for which block returns true.
reduce
Combines all elements by applying a binary operation.
find
Returns first element for which block is truthy.
each
Calls block once for each element.
each_with_index
Calls block with each element and its index.
include?
Returns true if array contains the element.
sort
Returns a new sorted array.
sort_by
Sorts using the value returned by the block.
reverse
Returns a new array with elements in reverse order.
flatten
Returns a new flattened array.
uniq
Returns a new array with duplicate values removed.
compact
Returns a new array with nil values removed.
first
Returns the first element(s).
last
Returns the last element(s).
take
Returns first n elements.
drop
Returns all elements after first n.
any?
Returns true if any element satisfies the block.
all?
Returns true if all elements satisfy the block.
count
Returns the count of elements.
sum
Returns the sum of all elements.
min
Returns the minimum element.
max
Returns the maximum element.
join
Returns a string of all elements joined.
split
Divides string into substrings based on delimiter.
upcase
Returns uppercase version of string.
downcase
Returns lowercase version of string.
strip
Returns string with leading/trailing whitespace removed.
gsub
Returns string with all occurrences of pattern replaced.
start_with?
Returns true if string starts with the given prefix.
end_with?
Returns true if string ends with the given suffix.
chars
Returns an array of characters.
keys
Returns an array of all keys.
values
Returns an array of all values.
fetch
Returns the value for key, or default if not found.
merge
Returns a new hash with combined contents.
key?
Returns true if key exists.
transform_values
Returns new hash with values transformed by block.