Ruby | Array length() function Last Updated : 06 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#length() : length() is a Array class method which returns the number of elements in the array. Syntax: Array.length() Parameter: Array Return: the number of elements in the array. Example #1 : Ruby # Ruby code for length() 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] # length method example puts "length() method form : #{a.length()}\n\n" puts "length() method form : #{b.length()}\n\n" puts "length() method form : #{c.length()}\n\n" Output : length() method form : 6 length() method form : 6 length() method form : 4 Example #2 : Ruby # Ruby code for length() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cat", nil] # declaring array b = ["cow", nil, "dog"] # length method example puts "length() method form : #{a.length()}\n\n" puts "length() method form : #{b.length()}\n\n" puts "length() method form : #{c.length()}\n\n" Output : length() method form : 3 length() method form : 3 length() method form : 2 Comment More infoAdvertise with us Next Article Ruby | Array length() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array one?() function Array#one?() : one?() is a Array class method which checks whether the array is having only one array element. Syntax: Array.one?() Parameter: Array Return: true - if array has only one element otherwise return false. Example #1 :Â Ruby # Ruby code for one?() method # declaring array a = [18, 22, 33 1 min read Ruby | Array <=> function Array#() : () is an Array class method which performs the comparison between the two arrays. Syntax: Array.() Parameter: Array for the comparison Return: 1 : if a > b -1 : if a < b 0 : if a = b Example #1 : Ruby # Ruby code for <=>() method # checking equality # declaring arrays a = [18, 2 min read Ruby | Array min() function Array#min() : min() is a Array class method which returns the minimum value in this array. Syntax: Array.min() Parameter: Array Return: the minimum value in this array. Example #1 : Ruby # Ruby code for min() method # declaring array a = %w[for geeks] # min method example puts "min() method for 1 min read Ruby | Array push() function Array#push() : push() is a Array class method which appends the given object(s) on to the end of this array. Syntax: Array.push() Parameter: Array Return: appends the given object(s) on to the end of this array. Example #1 : Ruby # Ruby code for push() method # declaring array a = [18, 22, 33, nil, 2 min read Ruby | Array none?() function Array#none?() : none?() is a Array class method which checks whether the array is empty or not. Syntax: Array.none?() Parameter: Array Return: true - if array has no elements otherwise return false Example #1 : Ruby # Ruby code for none?() method # declaring array a = [18, 22, 33, nil, 5, 6] # decla 1 min read Like