| Method | Example |
|---|---|
| map |
returns a new array after performing a block operation on each of the elements in the collection (1..4).map {|x| x+1}
|
| to_a |
Returns an array based on the argument passed into it (1..7).to_a |
| each |
Calls block once for each element in self, passing that element as a parameter a = [ "a", "b", "c" ] |
| each_with_index |
Yields all elements with their indices hash = Hash.new |
| each_slice |
Breaks collection into a group of n sized elements (1..9).each_slice(3) { |x| print x }
|
| include?(value) |
Returns true if any member of enum equals object array = [1,2,3,4] array.include?(4) |
| sort |
Returns array sorted by <=> operator or by block a = [ "d", "a", "e", "c", "b" ] |
| grep |
Returns an array of every element in enum for which Pattern === element ["Test", "Foo", "Bar"].grep 'Foo' |
| inject |
Easily allows users to add, multiply, subtract through each element of a collection (1..5).inject { |sum, element| sum + element }
|