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 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, 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 : [5, 6, 22, 33, 18, nil] shuffle!() method form : [1, 4, 9, 1, 1, 88] shuffle!() method form : [22, 6, 18, 50] 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 : ["nil", "dog", "abc"] shuffle!() method form : ["dog", "cow", nil] shuffle!() method form : ["cat", nil] 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 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] # d 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 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 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 Like