Ruby | Array replace() function Last Updated : 06 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#replace() : replace() is a Array class method which returns an array of all combinations of elements from all arrays. Syntax: Array.replace() Parameter: Array Return: an array of all combinations of elements from all arrays. Example #1 : Ruby # Ruby code for replace() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [2, 5] # replace method example a.replace(b) puts "replace() method form : #{a}\n\n" b.replace(c) puts "replace() method form : #{b}\n\n" c.replace(a) puts "replace() method form : #{c}\n\n" Output : replace() method form : [1, 4, 1, 1, 88, 9] replace() method form : [2, 5] replace() method form : [1, 4, 1, 1, 88, 9] Example #2 : Ruby # Ruby code for replace() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["hi"] # declaring array b = ["cow", nil, "dog"] # replace method example a.replace(b) puts "replace() method form : #{a}\n\n" b.replace(c) puts "replace() method form : #{b}\n\n" c.replace(a) puts "replace() method form : #{c}\n\n" Output : replace() method form : ["cow", nil, "dog"] replace() method form : ["hi"] replace() method form : ["cow", nil, "dog"] Comment More infoAdvertise with us Next Article Ruby | Array replace() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array pack() function Array#pack() : pack() is a Array class method which returns the contents of arr into a binary sequence according to the directives in aTemplateString Syntax: Array.pack() Parameter: Array Return: the contents of arr into a binary sequence according to the directives in aTemplateString Example #1 : R 1 min read Ruby | Array rotate() function Array#rotate() : rotate() is a Array class method which returns a new array by rotating self so that the element at count is the first element of the new array. Syntax: Array.rotate() Parameter: Array Return: a new array by rotating self so that the element at count is the first element of the new a 2 min read Ruby | Array rotate!() function Array#rotate!() : rotate!() is a Array class method which returns self rotated in place so that the element at count comes first, and returns self. Syntax: Array.rotate!() Parameter: Array Return: self rotated in place so that the element at count comes first, and returns self. Example #1 : Ruby # R 2 min read Ruby | Array reject!() function Array#reject!() : reject!() is a Array class method which returns a new array containing the values which are not returned by the block. Syntax: Array.reject!() Parameter: Array Return: a new array containing the values not returned by the block. Example #1 : Ruby # Ruby code for reject!() method # 1 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 Like