Ruby | Array transpose() function Last Updated : 06 Dec, 2019 Comments Improve Suggest changes Like Article Like Report Array#transpose() : transpose() is a Array class method which returns the length of elements in the array transposes the rows and columns. Syntax: Array.transpose() Parameter: Array Return: transposes the rows and columns. Example #1 : Ruby # Ruby code for transpose() method # declaring array a = [[18, 22], [33, 3, ], [5, 6]] # declaring array b = [[1, 4, 1, 1, 88, 9]] # transpose method example puts "transpose() method form : #{a.transpose()}\n\n" puts "transpose() method form : #{b.transpose()}\n\n" Output : transpose() method form : [[18, 33, 5], [22, 3, 6]] transpose() method form : [[1], [4], [1], [1], [88], [9]] Example #2 : Ruby # Ruby code for transpose() method # declaring array a = [["abc", "nil", "dog"]] # declaring array b = [["cow", "go", "dog"]] # transpose method example puts "transpose() method form : #{a.transpose()}\n\n" puts "transpose() method form : #{b.transpose()}\n\n" Output : transpose() method form : [["abc"], ["nil"], ["dog"]] transpose() method form : [["cow"], ["go"], ["dog"]] Comment More infoAdvertise with us Next Article Ruby | Array transpose() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array take() function Array#take() : take() is a Array class method which returns the number of elements in the array. Syntax: Array.take() Parameter: Array Return: the number of elements in the array. Example #1 : Ruby # Ruby code for take() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 1 min read Ruby | Array sample() function Array#sample() : sample() is a Array class method which returns a random element or n random elements from the array. Syntax: Array.sample() Parameter: Array Return: a random element or n random elements from the array. Example #1 : Ruby # Ruby code for sample() method # declaring array a = [18, 22, 1 min read Ruby | Array to_a() function Array#to_a() : to_a() is a Array class method which returns self array. Syntax: Array.to_a() Parameter: Array Return: self array representation Example #1 : Ruby # Ruby code for to_a() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c 1 min read Ruby | Array to_s() function Array#to_s() : to_s() is a Array class method which returns self array. Syntax: Array.to_s() Parameter: Array Return: self array Example #1 : Ruby # Ruby code for to_s() 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, 1 min read Ruby | Array to_h() function Array#to_h() : to_h() is a Array class method which returns the result of interpreting ary as an array of [key, value] pairs. Syntax: Array.to_h() Parameter: Array Return: the result of interpreting ary as an array of [key, value] pairs. Example #1 : Ruby # Ruby code for to_h() method # declaring ar 1 min read Like