<=>

ary other_ary â -1, 0, +1 or nil
Instance Public methods

Comparison â Returns an integer (-1, 0, or +1) if this array is less than, equal to, or greater than other_ary.

nil is returned if the two values are incomparable.

Each object in each array is compared (using the <=> operator).

Arrays are compared in an âelement-wiseâ manner; the first two elements that are not equal will determine the return value for the whole comparison.

If all the values are equal, then the return is based on a comparison of the array lengths. Thus, two arrays are âequalâ according to Array#<=> if, and only if, they have the same length and the value of each element is equal to the value of the corresponding element in the other array.

[ "a", "a", "c" ]    <=> [ "a", "b", "c" ]   #=> -1
[ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ]            #=> +1
doc_ruby_on_rails
2015-03-30 15:03:12
Comments
Leave a Comment

Please login to continue.