Ruby | Array rotate() function Last Updated : 06 Dec, 2019 Comments Improve Suggest changes Like Article Like Report Array#rotate() : rotate() is a Array class method which returns a new array by rotating self so that the element at count is the first element of the new array. Syntax: Array.rotate() Parameter: Array Return: a new array by rotating self so that the element at count is the first element of the new array. Example #1 : Ruby # Ruby code for rotate() 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] # rotate method example puts "rotate() method form : #{a.rotate(2)}\n\n" puts "rotate() method form : #{b.rotate(1)}\n\n" puts "rotate() method form : #{c.rotate(-1)}\n\n" Output : rotate() method form : [33, nil, 5, 6, 18, 22] rotate() method form : [4, 1, 1, 88, 9, 1] rotate() method form : [6, 18, 22, 50] Example #2 : Ruby # Ruby code for rotate() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cat", nil] # declaring array b = ["cow", nil, "dog"] # rotate method example puts "rotate() method form : #{a.rotate(2)}\n\n" puts "rotate() method form : #{b.rotate(1)}\n\n" puts "rotate() method form : #{c.rotate(-1)}\n\n" Output : rotate() method form : ["dog", "abc", "nil"] rotate() method form : [nil, "dog", "cow"] rotate() method form : [nil, "cat"] Comment More infoAdvertise with us Next Article Ruby | Array rotate() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array rotate!() function Array#rotate!() : rotate!() is a Array class method which returns self rotated in place so that the element at count comes first, and returns self. Syntax: Array.rotate!() Parameter: Array Return: self rotated in place so that the element at count comes first, and returns self. Example #1 : Ruby # R 2 min read Ruby | Array replace() function Array#replace() : replace() is a Array class method which returns an array of all combinations of elements from all arrays. Syntax: Array.replace() Parameter: Array Return: an array of all combinations of elements from all arrays. Example #1 : Ruby # Ruby code for replace() method # declaring array 2 min read Ruby | Array rindex() function Array#rindex() : rindex() is a Array class method which returns the index of the last object in the array. Syntax: Array.rindex() Parameter: Array Return: the index of the last object in the array. if not present then nil Example #1 : Ruby # Ruby code for rindex() method # declaring array a = [18, 2 1 min read Ruby | Array pack() function Array#pack() : pack() is a Array class method which returns the contents of arr into a binary sequence according to the directives in aTemplateString Syntax: Array.pack() Parameter: Array Return: the contents of arr into a binary sequence according to the directives in aTemplateString Example #1 : R 1 min read Ruby | Array permutation() function Array#permutation() : permutation() is a Array class method which returns all permutations of length n of the elements of the array, then return the array itself. Syntax: Array.permutation() Parameter: Array Return: all permutations of length n of the elements of the array, then return the array its 2 min read Like