Ruby | Array class each_index() operation Last Updated : 08 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#each_index() : each_index() is a Array class method which returns the index of the array element by following the condition in the given block once for each_index element in self. Syntax: Array.each_index() Parameter: block - condition to follow Return: index of the array element following the condition Code #1 : Example for each_index() method Ruby # Ruby code for each_index() method # declaring array a = ["abc", "nil", "dog"] # declaring array b = ["hello", "hi", "dog"] # each_index puts "each_index : #{a.each_index {|x| print x, " -- "}}\n\n" Output : 0 -- 1 -- 2 -- each_index : ["abc", "nil", "dog"] Code #2 : Example for each_index() method Ruby # Ruby code for each_index() method # declaring array a = ["abc", "nil", "dog"] # declaring array b = ["hello", "hi", "dog"] # each_index puts "each_index : #{b.each_index{|x| x = 2}}\n\n" Output : each_index : ["hello", "hi", "dog"] Comment More infoAdvertise with us Next Article Ruby | Array class each_index() operation M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Array-class Similar Reads Ruby | Array class each() operation Array#each() : each() is a Array class method which returns the array by following the condition in the given block once for each element in self. Syntax: Array.each() Parameter: block - condition to follow Return: Each array element following the condition Code #1 : Example for each() method Ruby # 1 min read Ruby | Array class find_index() operation Array#find_index() : find_index() is a Array class method which returns the index of the first array. If a block is given instead of an argument, returns the index of the first object for which the block returns true. Syntax: Array.find_index() Parameter: block - condition to follow Return: index va 1 min read Ruby | Array class fetch() operation Array#fetch() : fetch() is a Array class method which returns the element at the argument index position. Syntax: Array.fetch() Parameter: index value Return: element at the argument index value Code #1 : Example for fetch() method Ruby # Ruby code for fetch() method # declaring array a = [18, 22, 3 1 min read Ruby | Array class include?() operation Array#include?() : include?() is a Array class method checks if the argumented object is present in the array or not. Syntax: Array.include?() Parameter: obj - element to find Return: true - if the element is present; otherwise false Code #1 : Example for include?() method Ruby # Ruby code for inclu 1 min read Ruby | Array class eql?() operation Array#eql?() : eql?() is a Array class method which checks if the two arrays are equal or not. Syntax: Array.eql?() Parameter: Arrays to compare Return: true - if the arrays are equal; otherwise false Code #1 : Example for eql?() method Ruby # Ruby code for eql?() method # declaring array a = [18, 2 1 min read Like