Techie September 2022
1 . push()
Appends each argument in objects to the array and returns the array. This method is an alias for append method.
2 . pop()
Removes and returns trailing elements. When no argument is given and the array is not empty, it removes and returns the last element. And if the array is empty, it returns nil. When a non-negative Integer argument n is given and is in range, it removes and returns the last n elements in a new Array. If n is positive and out of range, it removes and returns all elements.
3 . permutation()
Returns the possible ordered arrangements of elements. The order of permutations is indeterminate. When a block and an in-range positive Integer argument n (0 < n <= Array.size) are given, calls the block with all n-tuple permutations of the array.
4 . product()
Returns an array of all combinations of elements from all arrays.
5 . pack()
Packs the contents of arr into a binary sequence according to the directives in aTemplateString.
6 . prepend
Prepends the given objects to the array. It is an alias for unshift method.
7 . partition
Returns an array of two arrays: The first having those elements for which the block returns a truthy value. The other having all other elements.
8 . private_methods
Returns the list of private methods accessible to obj. If the all parameter is set to false, only those methods in the receiver will be listed.
9 . public_methods
Returns the list of public methods accessible to obj. If the all parameter is set to false, only those methods in the receiver will be listed.
10 . rotate
Returns a new Array formed from the array with elements rotated from one end to the other.
-
When no argument given, it returns a new Array that is like the orginal array, except that the first element has been rotated to the last position.
-
When given a non-negative Integer count, it returns a new Array with count elements rotated from the beginning to the end.
-
If count is large, it uses count % array.size as the count.
-
If count is zero, it returns a copy of the array, unmodified.
-
When given a negative Integer count, it rotates in the opposite direction, from end to beginning.
-
If count is small (far from zero), uses count % array.size as the count.
-
rotate! method modifies the original array
11 . reject
Returns a new Array whose elements are all those from the original array for which the block returns false or nil.
- reject! method modifies the original array
12 . rassoc
Returns the first element in the array that is an Array whose second element == obj.
13 . repeated_permutation
Calls the block with each repeated permutation of length n of the elements of the array; each permutation is an Array; it then returns array. The order of the permutations is indeterminate.
When a block and a positive Integer argument n are given, it calls the block with each n-tuple repeated permutation of the elements of the array. The number of permutations is array.size**n.
14 . repeated_combination
Calls the block with each repeated combination of length n of the elements of the array; each combination is an Array; it then returns the array. The order of the combinations is indeterminate.
When a block and a positive Integer argument n are given, it calls the block with each n-tuple repeated combination of the elements of the array. The number of combinations is (n+1)(n+2)/2.
15 . reverse_each
Iterates backwards over array elements.
When a block is given, it passes, in reverse order, each element to the block then returns the array.
16 . rindex
Returns the index of the last element for which object == element.
When argument object is given but no block, returns the index of the last such element found.
Returns nil if no such object found. When a block is given but no argument, it calls the block with each successive element; returns the index of the last element for which the block returns a truthy value.
17 . replace
Replaces the content of the original array with the content of other_array and returns the array.
18 . reverse
Returns a new Array with the elements of the original array in reverse order.
- reverse! method modifies the original array
19 . reduce
Reduces an array to a single value by summing the elements.
20 . shift
Removes and returns leading elements. When no argument is given, it removes all other elements and returns the first element.
When positive Integer argument n is given, removes the first n elements then it returns those elements in a new Array.
If n is as large as or larger than array.length, removes all elements; returns those elements in a new Array.
21 . sort
Returns a new array with sorted elements from the original array.
With no block, compares elements using operator <=> (see Comparable):
- sort! method modifies the original array
22 . sort_by
With a block given, it returns an array of elements of the original array, sorted according to the value returned by the block for each element. The ordering of equal elements is indeterminate and may be unstable.
- sort_by! method modifies the original array
23 . select
Returns a new Array containing those elements of the original array for which the block returns a truthy value.
- select! method modifies the original array
24 . shuffle
Returns a new array with elements of the original array shuffled.
- shuffle! method modifies the original array
25 . sample
Returns random elements from the array. When no arguments are given, it returns a random element from the array.
When argument n is given, returns a new Array containing n random elements from the array.
26 . sum
Returns the sum of all the elements in the array. If a block is given, the block is applied to the array, then the sum is computed. If the array is empty, it returns init.
The elements need not be numeric, but must be +-compatible with each other and with init.
27 . size
Returns the count of elements in the array. This method is an alias for the length method.
28 . slice
returns a subarray specified by range of indices.
- slice! method modifies the original array
29 . slice_when
Partitions elements into arrays (“slices”); it calls the block with each element and its successor and begins a new slice if and only if the block returns a truthy value.
30 . slice_before
With argument pattern, returns an enumerator that uses the pattern to partition elements into arrays (“slices”). An element begins a new slice if element === pattern (or if it is the first element).
31 . slice_after
With argument pattern, returns an enumerator that uses the pattern to partition elements into arrays (“slices”). An element ends the current slice if element === pattern.
Thanks for reading, see you in the next one!