public Method

Array.==(p1)

array == other_array      bool

Equality—Two arrays are equal if they contain the same number of elements and if each element is equal to (according to Object.==) the corresponding element in the other array.

[ "a", "c" ]    == [ "a", "c", 7 ]     #=> false
[ "a", "c", 7 ] == [ "a", "c", 7 ]     #=> true
[ "a", "c", 7 ] == [ "a", "d", "f" ]   #=> false

Source Code

/* 
*  call-seq:
*     array == other_array   ->   bool
*
*  Equality---Two arrays are equal if they contain the same number
*  of elements and if each element is equal to (according to
*  Object.==) the corresponding element in the other array.
*
*     [ "a", "c" ]    == [ "a", "c", 7 ]     #=> false
*     [ "a", "c", 7 ] == [ "a", "c", 7 ]     #=> true
*     [ "a", "c", 7 ] == [ "a", "d", "f" ]   #=> false
*
*/

static VALUE
rb_ary_equal(ary1, ary2)
   VALUE ary1, ary2;
{
   long i;

   if (ary1 == ary2) return Qtrue;
   if (TYPE(ary2) != T_ARRAY) {
       if (!rb_respond_to(ary2, rb_intern("to_ary"))) {
           return Qfalse;
       }
       return rb_equal(ary2, ary1);
   }
   if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
   for (i=0; i<RARRAY(ary1)->len; i++) {
       if (!rb_equal(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i)))
           return Qfalse;
   }
   return Qtrue;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.