Ruby | Array reverse() function Last Updated : 06 Dec, 2019 Comments Improve Suggest changes Like Article Like Report Array#reverse() : reverse() is a Array class method which returns a new array containing self's elements in reverse order. Syntax: Array.reverse() Parameter: Array Return: a new array containing self's elements in reverse order. Example #1 : Ruby # Ruby code for reverse() 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] # reverse method example puts "reverse() method form : #{a.reverse()}\n\n" puts "reverse() method form : #{b.reverse()}\n\n" puts "reverse() method form : #{c.reverse()}\n\n" Output : reverse() method form : [6, 5, nil, 33, 22, 18] reverse() method form : [9, 88, 1, 1, 4, 1] reverse() method form : [6, 50, 22, 18] Example #2 : Ruby # Ruby code for reverse() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cat", nil] # declaring array b = ["cow", nil, "dog"] # reverse method example puts "reverse() method form : #{a.reverse()}\n\n" puts "reverse() method form : #{b.reverse()}\n\n" puts "reverse() method form : #{c.reverse()}\n\n" Output : reverse() method form : ["dog", "nil", "abc"] reverse() method form : ["dog", nil, "cow"] reverse() method form : [nil, "cat"] Comment More infoAdvertise with us Next Article Ruby | Array reverse() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array reverse!() function Array#reverse!() : reverse!() is a Array class method which returns reverses self in place Syntax: Array.reverse!() Parameter: Array Return: Reverses self in place Example #1 : Ruby # Ruby code for reverse!() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 1 min read Ruby | Array reverse_each() function Array#reverse_each() : reverse_each() is a Array class method which traverses self in reverse order. Syntax: Array.reverse_each() Parameter: Array Return: traverses self in reverse order. Example #1 : Ruby # Ruby code for reverse_each() method # declaring array a = [18, 22, 33, nil, 5, 6] # declarin 2 min read Ruby | reverse function The reverse function in Ruby is used to reverse the input array into another new array and keep the input array as it is before. Syntax: Array.reverse Here Array is the input array whose elements are to be reversed. Parameters: This function does not accept any parameters. Returns: the another new a 2 min read Ruby | reverse! function The reverse! function in Ruby is used to reverse the input array into the same array. Syntax: Array.reverse! Here Array is the input array whose elements are to be reversed.Parameters: This function does not accept any parameters.Returns: the same input array with reversed element. Example 1:  Rub 2 min read Ruby | Array reject!() function Array#reject!() : reject!() is a Array class method which returns a new array containing the values which are not returned by the block. Syntax: Array.reject!() Parameter: Array Return: a new array containing the values not returned by the block. Example #1 : Ruby # Ruby code for reject!() method # 1 min read Ruby | Array reject() function Array#reject() : reject() is a Array class method which returns new array containing the items in the array for which the given block is not true Syntax: Array.reject() Parameter: Array Return: new array containing the items in self for which the given block is not true Example #1 : Ruby # Ruby code 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 one?() function Array#one?() : one?() is a Array class method which checks whether the array is having only one array element. Syntax: Array.one?() Parameter: Array Return: true - if array has only one element otherwise return false. Example #1 : Ruby # Ruby code for one?() method # declaring array a = [18, 22, 33 1 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 rotate() function 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 a 2 min read Like