Ruby | reverse function Last Updated : 06 May, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 array of reversed elements of the input array. Example 1: Ruby # Initializing some arrays of elements Array1 = ["a", "b", "c", "d"] Array2 = [] Array3 = [1] Array4 = [1, 2] Array5 = ["Ram", "Geeta", "Shita"] # Calling to reverse function A = Array1.reverse B = Array2.reverse C = Array3.reverse D = Array4.reverse E = Array5.reverse # Printing the new reversed array puts "#{A}" puts "#{B}" puts "#{C}" puts "#{D}" puts "#{E}" Output: ["d", "c", "b", "a"] [] [1] [2, 1] ["Shita", "Geeta", "Ram"] Example 2: Ruby # Initializing some arrays of elements Array1 = ["a", "b", "c", "d"] Array2 = [] Array3 = [1] Array4 = [1, 2] Array5 = ["Ram", "Geeta", "Shita"] # Calling to reverse function A = Array1.reverse B = Array2.reverse C = Array3.reverse D = Array4.reverse E = Array5.reverse # Printing original input array puts "#{Array1}" puts "#{Array2}" puts "#{Array3}" puts "#{Array4}" puts "#{Array5}" Output: ["a", "b", "c", "d"] [] [1] [1, 2] ["Ram", "Geeta", "Shita"] Note: In the above example, it can be seen that after calling the reverse function it reverse the original input array into another array and keep the original array as it is before. Reference: https://devdocs.io/ruby~2.5/array#method-i-reverse Comment More infoAdvertise with us Next Article Ruby | Array reverse() function K Kanchan_Ray Follow Improve Article Tags : Ruby Ruby-Methods Similar Reads 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 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() function 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 2 min read Ruby | Integer - function The - is an inbuilt method in Ruby returns the subtraction of two numbers. It returns num1 - num2. Syntax: num1 - num2 Parameters: The function accepts no parameter. Return Value: It returns the subtraction of two numbers. Example 1: Ruby # Ruby program for - method in Integer # Initialize numbers n 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 | Matrix inverse() function The inverse() is an inbuilt method in Ruby returns the inverse of the given matrix. Syntax: mat1.inverse() Parameters: The function does not takes any parameter. Return Value: It returns the inverse of a matrix. Example 1: CPP #Ruby program for inverse() method in Matrix #Include matrix require 1 min read Like