shuffle

ary.shuffle â new_aryary.shuffle(random: rng) â new_ary Instance Public methods Returns a new array with elements of self shuffled. a = [ 1, 2, 3 ] #=> [1, 2, 3] a.shuffle #=> [2, 3, 1] The optional rng argument will be used as the random number generator. a.shuffle(random: Random.new(1)) #=> [1, 3, 2]

shuffle!

ary.shuffle! â aryary.shuffle!(random: rng) â ary Instance Public methods Shuffles elements in self in place. The optional rng argument will be used as the random number generator.

size

size() Instance Public methods Alias for: length

slice

ary.slice(index) â obj or nilary.slice(start, length) â new_ary or nilary.slice(range) â new_ary or nil Instance Public methods Element Reference â Returns the element at index, or returns a subarray starting at the start index and continuing for length elements, or returns a subarray specified by range of indices. Negative indices count backward from the end of the array (-1 is the last element). For start and range cases the starting index is just before a

slice!

ary.slice!(index) â obj or nilary.slice!(start, length) â new_ary or nilary.slice!(range) â new_ary or nil Instance Public methods Deletes the element(s) given by an index (optionally up to length elements) or by a range. Returns the deleted object (or objects), or nil if the index is out of range. a = [ "a", "b", "c" ] a.slice!(1) #=> "b" a #=> ["a", "c"] a.slice!(-1) #=> "c" a #=> ["a"] a.slice!(100) #=> nil a

sort

ary.sort â new_aryary.sort { |a, b| block } â new_ary Instance Public methods Returns a new array created by sorting self. Comparisons for the sort will be done using the <=> operator or using an optional code block. The block must implement a comparison between a and b, and return -1, when a follows b, 0 when a and b are equivalent, or +1 if b follows a. See also Enumerable#sort_by. a = [ "d", "a", "e", "c", "b" ] a.sort #=> ["a", "b

sort!

ary.sort! â aryary.sort! { |a, b| block } â ary Instance Public methods Sorts self in place. Comparisons for the sort will be done using the <=> operator or using an optional code block. The block must implement a comparison between a and b, and return -1, when a follows b, 0 when a and b are equivalent, or +1 if b follows a. See also Enumerable#sort_by. a = [ "d", "a", "e", "c", "b" ] a.sort! #=> ["a", "b", "c", "d", "e"] a.sort! { |

sort_by!

ary.sort_by! { |obj| block } â aryary.sort_by! â Enumerator Instance Public methods Sorts self in place using a set of keys generated by mapping the values in self through the given block. If no block is given, an Enumerator is returned instead.

take

ary.take(n) â new_ary Instance Public methods Returns first n elements from the array. If a negative number is given, raises an ArgumentError. See also #drop a = [1, 2, 3, 4, 5, 0] a.take(3) #=> [1, 2, 3]

take_while

ary.take_while { |arr| block } â new_aryary.take_while â Enumerator Instance Public methods Passes elements to the block until the block returns nil or false, then stops iterating and returns an array of all prior elements. If no block is given, an Enumerator is returned instead. See also #drop_while a = [1, 2, 3, 4, 5, 0] a.take_while { |i| i < 3 } #=> [1, 2]