Techie August 2022
1 . join()
Converts each element of the array to a string, separated by the given separator.
2 . keep_if()
Retains those elements for which the block returns a truthy value then deletes all other elements and returns the array.
3 . last()
Returns the last n elements in a new Array. When no argument is given, it returns the last element.
4 . length
Returns the count of elements in the array.
5 . map!
Calls the block with each element and replaces the element with the block’s return value. This method is an alias for collect! method.
6 . map
Calls the block with each element and returns a new array whose elements are the return values from the block. This method is an alias for collect method.
7 . minmax
Returns a new 2-element Array containing the minimum and maximum values from the array. When a block is given, the block must return an Integer. When no block is given, each element must respond to Comparable method.
8 . max
Returns one of the maximum-valued element from array. When a block is given, the block must return an Integer. When no block is given, each element must respond to Comparable method.
With an argument Integer n and no block, it returns a new array with at most n elements. With an argument n and a block, it returns a new array with at most n elements, in descending order per the block.
9 . min
Returns one of the minimum-valued element from array. When a block is given, the block must return an Integer. When no block is given, each element must respond to Comparable method.
With an argument Integer n and no block, it returns a new array with at most n elements. With an argument n and a block, it returns a new array with at most n elements, in ascending order per the block.
10 . min_by
Returns the elements for which the block returns the minimum values. With a block given and no argument, returns the element for which the block returns the minimum value.
With a block given and positive integer argument n given, returns an array containing the n elements for which the block returns minimum values.
11 . max_by
Returns the elements for which the block returns the maximum values. With a block given and no argument, returns the element for which the block returns the maximum value.
With a block given and positive integer argument n given, returns an array containing the n elements for which the block returns maximum values.
12 . minmax_by
Returns a 2-element array containing the elements for which the block returns minimum and maximum values.
13 . member?
Returns true if for some index i in array, obj == array[i]; otherwise false. This is an alias for include? method.
14 . methods
Returns a list of the names of public and protected methods of obj. This will include all the methods accessible in obj’s ancestors. If the optional parameter is false, it returns an array of obj’s public and protected singleton methods, the array will not include methods in modules included in obj.
15 . none?
Returns true if no element of the array meet a given criterion.
With no block given and no argument, returns true if the array has no truthy elements, false otherwise.
With a block given and no argument, calls the block with each element in the array and returns true if the block returns no truthy value, false otherwise.
If argument obj is given, returns true if obj.=== no element, false otherwise.
16 . nil?
Returns true if the array is empty. Only the object nil responds true to nil?.
17 . one?
Returns true if exactly one element of the array meets a given criterion.
With no block given and no argument, returns true if the array has exactly one truthy element, false otherwise.
With a block given and no argument, calls the block with each element in the array and returns true if the block yields a truthy value for exactly one element, false otherwise.
If argument obj is given, returns true if obj.=== exactly one element, false otherwise.
18 . object_id
Returns an integer identifier for obj.
Thanks for reading, see you in the next one!