End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Array#==
array == other_array → true or false
array.c
View on GitHub ↗
static VALUE
rb_ary_equal(VALUE ary1, VALUE ary2)
{
if (ary1 == ary2) return Qtrue;
if (!RB_TYPE_P(ary2, T_ARRAY)) {
if (!rb_respond_to(ary2, idTo_ary)) {
return Qfalse;
}
return rb_equal(ary2, ary1);
}
if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return Qfalse;
if (RARRAY_CONST_PTR_TRANSIENT(ary1) == RARRAY_CONST_PTR_TRANSIENT(ary2)) return Qtrue;
return rb_exec_recursive_paired(recursive_equal, ary1, ary2, ary2);
}
Returns true if both array.size == other_array.size and for each index i in array, array[i] == other_array[i]:
Example
a0 = [:foo, 'bar', 2] a1 = [:foo, 'bar', 2.0] a1 == a0 # => true [] == [] # => true
Otherwise, returns false.
This method is different from method Array#eql?, which compares elements using Object#eql?.