public Method

Stat.<=>(p1)

stat <→ other_stat     -1, 0, 1

Compares File::Stat objects by comparing their respective modification times.

f1 = File.new("f1", "w")
sleep 1
f2 = File.new("f2", "w")
f1.stat <=> f2.stat   #=> -1

Source Code

/*
*  call-seq:
*     stat <=> other_stat    => -1, 0, 1
*  
*  Compares <code>File::Stat</code> objects by comparing their
*  respective modification times.
*     
*     f1 = File.new("f1", "w")
*     sleep 1
*     f2 = File.new("f2", "w")
*     f1.stat <=> f2.stat   #=> -1
*/

static VALUE
rb_stat_cmp(self, other)
   VALUE self, other;
{
   if (rb_obj_is_kind_of(other, rb_obj_class(self))) {
       time_t t1 = get_stat(self)->st_mtime;
       time_t t2 = get_stat(other)->st_mtime;
       if (t1 == t2)
           return INT2FIX(0);
       else if (t1 < t2)
           return INT2FIX(-1);
       else
           return INT2FIX(1);
   }
   return Qnil;
}
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.