Ruby | Array zip() function Last Updated : 06 Dec, 2019 Comments Improve Suggest changes Like Article Like Report Array#zip() : zip() is a Array class method which Converts any arguments to arrays, then merges elements of self with corresponding elements from each argument. Syntax: Array.zip() Parameter: Array Return: merges elements of self with corresponding elements from each argument. Example #1 : Ruby # Ruby code for zip() 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] # zip method example puts "zip() method form : #{a.zip(b)}\n\n" puts "zip() method form : #{b.zip(c)}\n\n" puts "zip() method form : #{c.zip(c)}\n\n" Output : zip() method form : [[18, 1], [22, 4], [33, 1], [nil, 1], [5, 88], [6, 9]] zip() method form : [[1, 18], [4, 22], [1, 50], [1, 6], [88, nil], [9, nil]] zip() method form : [[18, 18], [22, 22], [50, 50], [6, 6]] Example #2 : Ruby # Ruby code for zip() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cat", nil] # declaring array b = ["cow", nil, "dog"] # zip method example puts "zip() method form : #{a.zip(b)}\n\n" puts "zip() method form : #{b.zip(c)}\n\n" puts "zip() method form : #{c.zip(c)}\n\n" Output : zip() method form : [["abc", "cow"], ["nil", nil], ["dog", "dog"]] zip() method form : [["cow", "cat"], [nil, nil], ["dog", nil]] zip() method form : [["cat", "cat"], [nil, nil]] Comment More infoAdvertise with us Next Article Ruby | Array zip() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array uniq() function Array#uniq() : uniq() is a Array class method which returns a new array by removing duplicate values in the array. Syntax: Array.uniq() Parameter: Array Return: a new array by removing duplicate values in the array Example #1 : Ruby # Ruby code for uniq() method # declaring array a = [18, 22, 33, ni 2 min read Ruby | Array uniq!() function Array#uniq!() : uniq!() is a Array class method which removes duplicate elements from the array and returns only if there is duplicate element in the array. Syntax: Array.uniq!() Parameter: Array Return: removes duplicate elements from the array. Example #1 : Ruby # Ruby code for uniq!() method # de 1 min read Ruby | Array slice() function Array#slice() : slice() is a Array class method which returns a subarray specified by range of indices. Syntax: Array.slice() Parameter: Array Return: a subarray specified by range of indices. Example #1 : Ruby # Ruby code for slice() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring 1 min read Ruby | Array slice!() function Array#slice!() : slice!() is a Array class method which seletes the element(s) given by an index or by a range. Syntax: Array.slice!() Parameter: Array Return: Deletes the elements given by an index or by a range. Example #1 : Ruby # Ruby code for slice!() method # declaring array a = [18, 22, 33, n 2 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 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 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 sort() function Array#sort() : sort() is a Array class method which returns a new array created by sorting self Syntax: Array.sort() Parameter: Array Return: a new array created by sorting self Example #1 : Ruby # Ruby code for sort() method # declaring array a = ["abc", "nil", "dog"] 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