Ruby | Array combination() operation Last Updated : 10 Feb, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#combination() : combination() is an Array class method which invokes with a block yielding all combinations of length 'n' of elements of the array. Syntax: Array.combination() Parameter: Arrays in which we want elements to be invoked Return: all combinations of length 'n' of elements of the array. Code #1 : Example for combination() method Ruby # Ruby code for combination() method # declaring array a = [1, 2, 56, 23] # combination of length 2 puts "combination a : #{a.combination(2).to_a}\n\n" # combination of length 3 puts "combination a : #{a.combination(3).to_a}\n\n" Output : combination a : [[1, 2], [1, 56], [1, 23], [2, 56], [2, 23], [56, 23]] combination a : [[1, 2, 56], [1, 2, 23], [1, 56, 23], [2, 56, 23]] Code #2 : Example for combination() method Ruby # Ruby code for combination() method # declaring array a = [[1, 2, 56, 23], [34, 54, 23, 1]] # combination of length 2 puts "collect a : #{a.combination(2).to_a}\n\n" # combination of length 1 puts "collect a : #{a.combination(1).to_a}\n\n" Output : collect a : [[[1, 2, 56, 23], [34, 54, 23, 1]]] collect a : [[[1, 2, 56, 23]], [[34, 54, 23, 1]]] Comment More infoAdvertise with us Next Article Ruby | Array combination() operation M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Array-class Similar Reads Ruby | Array concat() operation Array#concat() : concat() is a Array class method which returns the array after appending the two arrays together. Syntax: Array.concat() Parameter: Arrays to be combined Return: Append the two arrays Code #1 : Example for concat() method Ruby # Ruby code for concat() method # adding elements at the 2 min read Ruby | Array compact!() operation Array#compact! () : compact! () is a Array class method which returns the array after removing all the 'nil' value elements (if any) from the array. If there are no nil values in the array it returns back the nil value. Syntax: Array.compact!() Parameter: Array to remove the 'nil' value from. Return 2 min read Ruby | Array compact() operation Array#compact () : compact () is a Array class method which returns the array after removing all the 'nil' value elements (if any) from the array. Syntax: Array.compact() Parameter: Array to remove the 'nil' value from. Return: removes all the nil values from the array. Code #1 : Example for compact 2 min read Ruby | Array count() operation Array#count() : count() is a Array class method which returns the number of elements in the array. It can also find the total number of a particular element in the array. Syntax: Array.count() Parameter: obj - specific element to found Return: removes all the nil values from the array. Code #1 : Exa 2 min read Ruby | Array at() operation Array#at() : at() is an Array class method which returns the element at the specific argumented index value. Syntax: Array.at() Parameter: - Arrays to search elements. - index to search Return: Array element at a specific index value Code #1 : Example for at() method Ruby # Ruby code for at() method 1 min read Like