Ruby | Array shuffle() function Last Updated : 06 Dec, 2019 Comments Improve Suggest changes Like Article Like Report Array#shuffle() : shuffle() is a Array class method which returns a new array with elements of self shuffle. Syntax: Array.shuffle() Parameter: Array Return: a new array with elements of self shuffle Example #1 : Ruby # Ruby code for shuffle() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, 50, 6] # shuffle method example puts "shuffle() method form : #{a.shuffle()}\n\n" puts "shuffle() method form : #{b.shuffle()}\n\n" puts "shuffle() method form : #{c.shuffle()}\n\n" Output : shuffle() method form : [22, 5, 6, nil, 33, 18] shuffle() method form : [4, 88, 9, 1, 1, 1] shuffle() method form : [50, 18, 22, 6] Example #2 : Ruby # Ruby code for shuffle() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cat", nil] # declaring array b = ["cow", nil, "dog"] # shuffle method example puts "shuffle() method form : #{a.shuffle()}\n\n" puts "shuffle() method form : #{b.shuffle()}\n\n" puts "shuffle() method form : #{c.shuffle()}\n\n" Output : shuffle() method form : ["abc", "dog", "nil"] shuffle() method form : ["dog", "cow", nil] shuffle() method form : [nil, "cat"] Comment More infoAdvertise with us Next Article Ruby | Array shuffle() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array shuffle!() function Array#shuffle!() : shuffle!() is a Array class method which shuffles elements in self in place. Syntax: Array.shuffle!() Parameter: Array Return: shuffles elements in self in place. Example #1 : Ruby # Ruby code for shuffle!() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b 1 min read Ruby | Array shift() function Array#shift() : shift() is a Array class method which removes the first element of self and returns it or nil if the array is empty. Syntax: Array.shift() Parameter: Array Return: removes the first element of self and returns it or nil if the array is empty. Example #1 : Ruby # Ruby code for shift() 2 min read Ruby | Array slice!() function Array#slice!() : slice!() is a Array class method which seletes the element(s) given by an index or by a range. Syntax: Array.slice!() Parameter: Array Return: Deletes the elements given by an index or by a range. Example #1 : Ruby # Ruby code for slice!() method # declaring array a = [18, 22, 33, n 2 min read Ruby | Array slice() function Array#slice() : slice() is a Array class method which returns a subarray specified by range of indices. Syntax: Array.slice() Parameter: Array Return: a subarray specified by range of indices. Example #1 : Ruby # Ruby code for slice() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring 1 min read Ruby | Array sample() function Array#sample() : sample() is a Array class method which returns a random element or n random elements from the array. Syntax: Array.sample() Parameter: Array Return: a random element or n random elements from the array. Example #1 : Ruby # Ruby code for sample() method # declaring array a = [18, 22, 1 min read Ruby | Array select!() function Array#select!() : select!() is a Array class method which returns the given block passing in successive elements from self, deleting elements for which the block returns a false value. Syntax: Array.select!() Parameter: Array Return: the given block passing in successive elements from self, deleting 2 min read Ruby | Array select() function Array#select() : select() is a Array class method which returns a new array containing all elements of array for which the given block returns a true value. Syntax: Array.select() Parameter: Array Return: A new array containing all elements of array for which the given block returns a true value. Ex 2 min read Ruby | Array unshift() function Array#unshift() : unshift() is a Array class method which returns the shifted array with argumented element in place. Syntax: Array.unshift()Parameter: ArrayReturn: the shifted array with argumented element in place. Example #1 : Ruby # Ruby code for unshift() method # declaring array a = [18, 22, 3 2 min read Ruby | Array sort() function Array#sort() : sort() is a Array class method which returns a new array created by sorting self Syntax: Array.sort() Parameter: Array Return: a new array created by sorting self Example #1 : Ruby # Ruby code for sort() method # declaring array a = ["abc", "nil", "dog"] 1 min read Ruby | Array uniq() function Array#uniq() : uniq() is a Array class method which returns a new array by removing duplicate values in the array. Syntax: Array.uniq() Parameter: Array Return: a new array by removing duplicate values in the array Example #1 : Ruby # Ruby code for uniq() method # declaring array a = [18, 22, 33, ni 2 min read Like