Ruby | reverse! function Last Updated : 29 Jul, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: Ruby # Initializing some arrays of elements Array1 = ["a", "b", "c", "d"] Array2 = [] Array3 = [1] Array4 = [1, 2] Array5 = ["Ram", "Geeta", "Shita"] # Calling reverse! function A = Array1.reverse! B = Array2.reverse! C = Array3.reverse! D = Array4.reverse! E = Array5.reverse! # Printing the same input array # with reversed elements puts "#{A}" puts "#{B}" puts "#{C}" puts "#{D}" puts "#{E}" Output: ["d", "c", "b", "a"] [] [1] [2, 1] ["Shita", "Geeta", "Ram"] Example 2: javascript # Initializing some arrays of elements Array1 = ["a", "b", "c", "d"] Array2 = [] Array3 = [1] Array4 = [1, 2] Array5 = ["Ram", "Geeta", "Shita"] # Calling reverse! function A = Array1.reverse! B = Array2.reverse! C = Array3.reverse! D = Array4.reverse! E = Array5.reverse! # Printing original input array # after calling reverse! function puts "#{Array1}" puts "#{Array2}" puts "#{Array3}" puts "#{Array4}" puts "#{Array5}" Output: ["d", "c", "b", "a"] [] [1] [2, 1] ["Shita", "Geeta", "Ram"] Note: Difference between reverse and reverse! functions is that reverse function reverses the input array elements into another array and keep the input array as it is but the reverse! function reverses the input array into the same input array.Reference: https://devdocs.io/ruby~2.5/array#method-i-reverse-21 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 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 | 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