Techie October 2022
1 . to_h
Returns a new hash formed from the array.
When a block is given, it calls the block with each array element and the block must return a 2-element Array whose two elements form a key-value pair in the returned Hash.
When no block is given, the array must be an array of 2-element sub-arrays, each sub-array is formed into a key-value pair in the new Hash.
2 . transpose
Transposes the rows and columns in an array of arrays. The nested arrays must all be the same size.
3 . take()
Returns a new array containing the first n element of the given array, where n is a non-negative Integer. It does not modify the original array.
4 . take_while
Returns a new array containing zero or more leading elements of the array. It does not modify the original array.
With a block given, calls the block with each successive element of the array and stops if the block returns false or nil. It then returns a new array containing those elements for which the block returned a truthy value.
5 . to_s
This method is an alias for inspect method.
Returns the new String formed from each array element.
6 . to_set
Converts the array to a set.
7 . tally
Counts element occurences in the array.
With a hash argument, that hash is used for the tally (instead of a new hash), and is returned. This may be useful for accumulating tallies across multiple enumerables.
8 . tap
Taps into a method chain, in order to perform operations on intermediate results within the chain.
9 . then
Yields the array to the block and returns the result of the block.
10 . to_enum
Protects an array from being modified by some_method.
11 . union
Returns a new array that is the union of the given and all other arrays. Duplicates are removed, the order is preserved and items are compared using eql?
12 . unshift
Prepends the given objects to the array. Alias for prepend method.
13 . uniq
Returns a new array containing those elements from the array that are not duplicates, the first occurrence always being retained.
With a block given, it calls the block for each element and identifies (using method eql?) and omits duplicate values, that is, those elements for which the block returns the same value.
14 . values_at
Returns a new array whose elements are the elements of the array at the given Integer or Range indexes.
15 . yield_self
Yields the array to the block and returns the result of the block.
16 . zip
Merges elements of the array with corresponding elements from each argument.
Thanks for reading, see you in the next one!