reverse!

ary.reverse! â ary Instance Public methods Reverses self in place. a = [ "a", "b", "c" ] a.reverse! #=> ["c", "b", "a"] a #=> ["c", "b", "a"]

reverse_each

ary.reverse_each { |item| block } â aryary.reverse_each â Enumerator Instance Public methods Same as #each, but traverses self in reverse order. a = [ "a", "b", "c" ] a.reverse_each {|x| print x, " " } produces: c b a

rindex

ary.rindex(obj) â int or nilary.rindex { |item| block } â int or nilary.rindex â Enumerator Instance Public methods Returns the index of the last object in self == to obj. If a block is given instead of an argument, returns the index of the first object for which the block returns true, starting from the last object. Returns nil if no match is found. See also #index. If neither block nor argument is given, an Enumerator is returned instead. a = [ "a

rotate

ary.rotate(count=1) â new_ary Instance Public methods Returns a new array by rotating self so that the element at count is the first element of the new array. If count is negative then it rotates in the opposite direction, starting from the end of self where -1 is the last element. a = [ "a", "b", "c", "d" ] a.rotate #=> ["b", "c", "d", "a"] a #=> ["a", "b", "c", "d"] a.rotate(2) #=> ["c", "d", "a", "b"] a.rotate(-3) #=> ["b", "c", "d

rotate!

ary.rotate!(count=1) â ary Instance Public methods Rotates self in place so that the element at count comes first, and returns self. If count is negative then it rotates in the opposite direction, starting from the end of the array where -1 is the last element. a = [ "a", "b", "c", "d" ] a.rotate! #=> ["b", "c", "d", "a"] a #=> ["b", "c", "d", "a"] a.rotate!(2) #=> ["d", "a", "b", "c"] a.rotate!(-3) #=> ["a", "b", "c", "d"]

sample

ary.sample â objary.sample(random: rng) â objary.sample(n) â new_aryary.sample(n, random: rng) â new_ary Instance Public methods Choose a random element or n random elements from the array. The elements are chosen by using random and unique indices into the array in order to ensure that an element doesn't repeat itself unless the array already contained duplicate elements. If the array is empty the first form returns nil and the second form retu

select

ary.select { |item| block } â new_aryary.select â Enumerator Instance Public methods Returns a new array containing all elements of ary for which the given block returns a true value. If no block is given, an Enumerator is returned instead. [1,2,3,4,5].select { |num| num.even? } #=> [2, 4] a = %w{ a b c d e f } a.select { |v| v =~ /[aeiou]/ } #=> ["a", "e"] See also Enumerable#select.

select!

ary.select! {|item| block } â ary or nilary.select! â Enumerator Instance Public methods Invokes the given block passing in successive elements from self, deleting elements for which the block returns a false value. If changes were made, it will return self, otherwise it returns nil. See also #keep_if If no block is given, an Enumerator is returned instead.

shelljoin

array.shelljoin => string Instance Public methods Builds a command line string from an argument list array joining all elements escaped for Bourne shell and separated by a space. See Shellwords.shelljoin for details.

shift

ary.shift â obj or nilary.shift(n) â new_ary Instance Public methods Removes the first element of self and returns it (shifting all other elements down by one). Returns nil if the array is empty. If a number n is given, returns an array of the first n elements (or less) just like array.slice!(0, n) does. With ary containing only the remainder elements, not including what was shifted to new_ary. See also #unshift for the opposite effect. args = [ "-m", "-q", "filename" ] args.sh