Ruby | Array <=> function Last Updated : 05 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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, 22, 33, 4, 5, 6] # declaring arrays b = [18, 22, 33, 4, 5, 6] # declaring arrays c = [18, 22, 33, 40, 50, 6] # <=> method puts "<=> method : #{a <=> b}\n\n" # <=> method puts "<=> method : #{a <=> c}\n\n" # <=> method puts "<=> method : #{b <=> c}\n\n" Output : method : 0 method : -1 method : -1 Example #2 : Ruby # Ruby code for <=>() method # checking equality # declaring arrays a = ["abc", "xyz", "dog"] # declaring arrays b = ["cat", "cat", "dog"] # declaring arrays c = ["cat", "cat", "dog"] # <=> method puts "<=> method : #{a <=> b}\n\n" # <=> method puts "<=> method : #{a <=> c}\n\n" # <=> method puts "<=> method : #{b <=> c}\n\n" Output : method : -1 method : -1 method : 0 Comment More infoAdvertise with us Next Article Ruby | Array <=> function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array length() function 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 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 map() function Array#map() : map() is a Array class method which returns a new array containing the values returned by the block. Syntax: Array.map() Parameter: Array Return: a new array containing the values returned by the block. Example #1 : Ruby # Ruby code for map() method # declaring array a = [18, 22, 33, 3 2 min read 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 pop() function Array#pop() : pop() is a Array class method which checks removes the last element from the array and returns it. Syntax: Array.pop() Parameter: Array Return: removes the last element from the array and returns it. Example #1 : Ruby # Ruby code for pop() method # declaring array a = [18, 22, 33, nil, 1 min read Like