Ruby | reverse! function Last Updated : 29 Jul, 2021 Comments Improve Suggest changes 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 | 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 Ruby | Hash invert() function Hash#invert() is a Hash class method which gives the hash by reverting keys to values and values to key. Syntax: Hash.invert() Parameter: Hash values Return: hash by reverting keys to values and values to key Example #1 : Ruby # Ruby code for Hash.invert() method # declaring Hash value a = {a:100, b 2 min read Ruby | pop() function The pop() function in Ruby is used to pop or remove the last element of the given array and returns the removed elements. Syntax: pop(Elements) Parameters: Elements : This is the number of elements which are to be removed from the end of the given array. If this parameter is not used then it removes 1 min read Ruby | Queue pop() function The pop() is an inbuilt function in Ruby returns the element in the front of the queue and removes it from the queue. Syntax: q_name.pop() Parameters: The function does not takes any element. Return Value: It returns the first element which is at the front of the queue and removes it from the queue. 1 min read Ruby | Enumerable reverse_each() function The reverse_each() of enumerable is an inbuilt method in Ruby returns the elements of the temporary array. The temporary array contains the enumerable in reverse order. It returns an enumerator if no block is given. Syntax: enu.reverse_each { |obj| block } Parameters: The function accepts a block. R 1 min read Like